benchew0904 Posted December 26, 2011 Share Posted December 26, 2011 I'm new to PHP, can anyone can help me with auto sending email? I have a database which store my customer data which includes their next appointment date etc and I would like to auto send an email reminder to them. I have some problem with the script and I'm not sure it's work. My email script "To", I'm not sure how should I state the recipient email as there might be a few customers which have the same appointment date. Please do advise on my code. <?php include 'cogfig.php'; #here store all my connection $sql = "select email from user where appointment_date <= CURRENT_DATE and appointment_date >= ( CURRENT_DATE - INTERVAL 1 day )"; while (mysql_fetch_array($results)) { if ($query) { $to = $subject = "Appointment Reminder"; $message = "Dear Customer \n\n" . "We would like to inform you that your appointment is tomorrow. \n" . "Your Sincerely\n" . "Admin"; $from = "[email protected]"; $headers = "From: $from"; $sentMail = mail($to, $subject, $message, $headers); if ($sentMail) { $statusMessage = "Appointment Reminder Successfully Sent. \n"; } else { $statusMessage = "Appointment Reminder Unsuccessfully Sent"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253866-auto-send-email-reminder/ Share on other sites More sharing options...
scootstah Posted December 27, 2011 Share Posted December 27, 2011 Considering it is a loop, just put the email from the database and it will email everyone with an appointment on that day. Quote Link to comment https://forums.phpfreaks.com/topic/253866-auto-send-email-reminder/#findComment-1301532 Share on other sites More sharing options...
benchew0904 Posted December 27, 2011 Author Share Posted December 27, 2011 Considering it is a loop, just put the email from the database and it will email everyone with an appointment on that day. Sorry, I'm not strong in programming. What do you mean by "just put the email from the database and it will email everyone with an appointment on that day."? You mean put at "$To = "? Quote Link to comment https://forums.phpfreaks.com/topic/253866-auto-send-email-reminder/#findComment-1301569 Share on other sites More sharing options...
peter_anderson Posted December 27, 2011 Share Posted December 27, 2011 First off, your query isn't executing. And I'm unsure if it would run. Secondly, your loop should be while($row = mysql_fetch_array($results){ Your while loop states that for every result, it should do the code within the loop. For example, if there are 3 emails (bob@example, jim@example, me@example), it will do bob@example first, then jim, then me. As it is looping through each result, you should set to: $to = $row['email']; Quote Link to comment https://forums.phpfreaks.com/topic/253866-auto-send-email-reminder/#findComment-1301570 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.