Skip to content

Commit

Permalink
users select time for emails. #45
Browse files Browse the repository at this point in the history
  • Loading branch information
FardinApurbo committed May 5, 2023
1 parent e628109 commit 3a25196
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 12 deletions.
32 changes: 32 additions & 0 deletions PHP/reminder_11.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// Set the time zone to your desired time zone
date_default_timezone_set('America/New_York');

// Set the desired time for the email to be sent in 24-hour format (e.g. "14:30")
$send_time = '14:30';

// Get the current date and time
$current_time = date('H:i');

// If the current time matches the desired send time, send the email
if ($current_time == $send_time) {
// Set the recipient email address
$recipient_email = "[email protected]";

// Set the email subject
$subject = "Email Subject";

// Set the email message
$message = "Email Message";

// Set the email headers
$headers = "From: [email protected]\r\n";
$headers .= "Reply-To: [email protected]\r\n";
$headers .= "Cc: [email protected]\r\n";
$headers .= "Bcc: [email protected]\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

// Send the email
mail($recipient_email, $subject, $message, $headers);
}
?>
Binary file modified node_modules/.cache/default-development/1.pack
Binary file not shown.
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Edit from './components/Edit/Edit';
import Reset from './components/Reset/Reset';
import Resetcode from './components/Reset/Resetcode'
import Reenter from './components/Reset/Reenter'
import EmailReminder from './components/Emails/EmailReminder'

import {HabitProvider} from './components/contexts/HabitContext';

Expand Down Expand Up @@ -49,6 +50,7 @@ function App() {
<Route path="/CSE442-542/2023-Spring/cse-442q/reset" element={<Reset />} />
<Route path="/CSE442-542/2023-Spring/cse-442q/resetcode" element={<Resetcode />} />
<Route path="/CSE442-542/2023-Spring/cse-442q/reenter" element={<Reenter />} />
<Route path="/CSE442-542/2023-Spring/cse-442q/email" element={<EmailReminder />} />
</Routes>
</HabitProvider>
</div>
Expand Down
83 changes: 83 additions & 0 deletions src/components/Emails/EmailReminder.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

import { Link, useNavigate } from "react-router-dom";
import Navbar from '../Homepage/Navbar';
import './emailreminder.css'
import React, { useState } from "react";
import axios from "axios";

function EmailReminder() {
const [recipientEmail, setRecipientEmail] = useState("");
const [emailSubject, setEmailSubject] = useState("");
const [emailMessage, setEmailMessage] = useState("");
const [dateTime, setDateTime] = useState("");

const handleSubmit = async (event) => {
event.preventDefault();

const data = new FormData();
data.append("recipient_email", recipientEmail);
data.append("email_subject", emailSubject);
data.append("email_message", emailMessage);
data.append("date_time", dateTime);

try {
const response = await axios.post("send_email.php", data, {
headers: { "Content-Type": "multipart/form-data" },
});

console.log(response.data);
} catch (error) {
console.error(error);
}
};

return (
<div>
<Navbar />
<form className="container" onSubmit={handleSubmit}>
<label htmlFor="recipient_email">Recipient Email</label>
<input
type="email"
id="recipient_email"
name="recipient_email"
value={recipientEmail}
onChange={(event) => setRecipientEmail(event.target.value)}
/>
<br />

<label htmlFor="email_subject">Email Subject</label>
<input
type="text"
id="email_subject"
name="email_subject"
value={emailSubject}
onChange={(event) => setEmailSubject(event.target.value)}
/>
<br />

<label htmlFor="email_message">Email Message</label>
<textarea
id="email_message"
name="email_message"
value={emailMessage}
onChange={(event) => setEmailMessage(event.target.value)}
/>
<br />

<label htmlFor="date_time">Date and Time to Send</label>
<input
type="datetime-local"
id="date_time"
name="date_time"
value={dateTime}
onChange={(event) => setDateTime(event.target.value)}
/>
<br />

<button type="submit">Send Email</button>
</form>
</div>
);
}

export default EmailReminder;
57 changes: 57 additions & 0 deletions src/components/Emails/emailreminder.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}

.title {
font-size: 36px;
font-weight: bold;
margin-bottom: 24px;
}

.form-group {
margin-bottom: 16px;
}

.form-label {
display: block;
font-size: 18px;
font-weight: bold;
margin-bottom: 8px;
}

.form-input {
padding: 8px;
font-size: 16px;
width: 100%;
border: none;
border-radius: 4px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}

.form-textarea {
padding: 8px;
font-size: 16px;
width: 100%;
height: 120px;
border: none;
border-radius: 4px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
}

.form-button {
background-color: #007bff;
color: white;
padding: 8px 16px;
font-size: 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}

.form-button:hover {
background-color: #0069d9;
}
2 changes: 2 additions & 0 deletions src/components/Homepage/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default function Navbar() {

const routeStatistics = () => {navigate('/CSE442-542/2023-Spring/cse-442q/statistics')}
const routeFAQ = () => {navigate('/CSE442-542/2023-Spring/cse-442q/information')}
const routeEmail = () => {navigate('/CSE442-542/2023-Spring/cse-442q/email')}
const routeLogout = () => {
sessionStorage.clear();
setUser({})
Expand All @@ -68,6 +69,7 @@ export default function Navbar() {
<div className='app_button_div'>
{checkPath("statistics") ? <p id="current_tab" onClick={routeStatistics}>Statistics</p> : <p onClick={routeStatistics}>Statistics</p>}
{checkPath("information") ? <p id="current_tab" onClick={routeFAQ}>FAQ</p> : <p onClick={routeFAQ}>FAQ</p>}
{checkPath("email") ? <p id="current_tab" onClick={routeEmail}>Email Reminder</p> : <p onClick={routeEmail}>Email Reminder</p>}
</div>
<div className='profile_nav_div'>
<img src={pepe} alt="avatar"></img>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function Login() {
const makePost = async() => {
await axios({
method: "post",
url: "http://localhost:8000/login.php",
//url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/login.php",
// url: "http://localhost:8000/login.php",
url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/login.php",
data: {
username: username,
password: password,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Registration/ChooseHabits.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function ChooseHabits() {
let bad_habits_object = makeObject(habitList.habitsToStop, false);
await axios({
method: "post",
url: "http://localhost:8000/addhabit.php",
// url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/addhabit.php",
// url: "http://localhost:8000/addhabit.php",
url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/addhabit.php",
data: {
id: state.user,
good_habits: good_habits_object,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Registration/Signin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ function Signin() {
const makePost = async() => {
await axios({
method: "post",
url: "http://localhost:8000/insert.php",
// url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/insert.php",
// url: "http://localhost:8000/insert.php",
url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/insert.php",
data: {
username: username,
email: email,
Expand Down
12 changes: 6 additions & 6 deletions src/components/contexts/HabitContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ export const HabitProvider = ({ children }) => {
let username = "";

await axios
.get("http://localhost:8000/user.php?userid="+ userid)
// .get("https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/user.php?userid="+ userid)
// .get("http://localhost:8000/user.php?userid="+ userid)
.get("https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/user.php?userid="+ userid)
.then(function (response) {
// successful call will replace user object with correct information
// console.log("success");
Expand Down Expand Up @@ -418,8 +418,8 @@ export const HabitProvider = ({ children }) => {
let userid = 0;

await axios
.get("http://localhost:8000/returnid.php?userid="+ username)
// .get("https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/returnid.php?userid="+ username)
// .get("http://localhost:8000/returnid.php?userid="+ username)
.get("https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/returnid.php?userid="+ username)
.then(function (response) {
// successful call will replace user object with correct information
// console.log("success");
Expand Down Expand Up @@ -462,8 +462,8 @@ export const HabitProvider = ({ children }) => {
let result = true;
await axios({
method: "post",
url: "http://localhost:8000/addhabit.php",
// url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/addhabit.php",
// url: "http://localhost:8000/addhabit.php",
url: "https://www-student.cse.buffalo.edu/CSE442-542/2023-Spring/cse-442q/addhabit.php",
data: {
id: id,
good_habits: g,
Expand Down

0 comments on commit 3a25196

Please sign in to comment.