Hi everyone. Am trying to send email reminder for users to update their progress 1 month before end of every quarter. So every February and May etc the email notification will be autosend to the users from the system. Below is the code. Please advise if this is the correct way of doing it or if there is any better way. Thanks a lot.
<?php
$month= $row['MONTH(CURRENT_DATE())'];
//get email address's
$con=mysqli_connect("localhost","user","","pq");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT email FROM tuser");
while($row = mysqli_fetch_array($result))
{
if('$month'==2){
$to=$row['name']." <".$row['email'].">\r\n";
$subject="Please find this friendly reminder to update your Operational progress.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="To: ".$row['name']." <".$row['email'].">\r\n";
$headers .= "From: system <system@edu.com>" . "\r\n";
mail($to, $subject, $email, $headers);
}
elseif('$month'==5){
$to=$row['name']." <".$row['email'].">\r\n";
$subject="Please find this friendly reminder to update your Operational progress.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .="To: ".$row['name']." <".$row['email'].">\r\n";
$headers .= "From: system <system@edu.com>" . "\r\n";
mail($to, $subject, $email, $headers);
}
}
mysqli_close($con);
?>
Sophia_1
0
Junior Poster in Training
Recommended Answers
Jump to PostHi,
small note: in your IF statementes
if('$month'==2)
(and co.) you are comparing literally the word $month, not his value, against the integer. Single quotes will NOT parse the variable, so in this case you can remove them and write:if($month == 2)
Or with …
Jump to PostI'm referring at the IF/ELSEIF statements at lines 17 and 26.
All 5 Replies
cereal
1,524
Nearly a Senior Poster
Featured Poster
Sophia_1
0
Junior Poster in Training
cereal
1,524
Nearly a Senior Poster
Featured Poster
Sophia_1
0
Junior Poster in Training
cereal
1,524
Nearly a Senior Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.