Silver Mountain Posted June 23, 2010 Share Posted June 23, 2010 Hello, I am trying to email my customers with appointment reminders - however, my script will send the email to the last email in the query. What is happening with this script is the last email in the loop is receiving everyones appointments in addition to their appointment. I need each person that has an upcoming appointment receive an email with just their information from the database in the message of the email. <code> $query_notifier = "SELECT users.email_address, users.username, artists.nick_name, artist.follow_up_date, DATE_FORMAT(follow_up_date, '%b %d, %Y') AS hmfollow_up_date FROM users INNER JOIN artists ON users.username = artists.username WHERE internal_parasite.follow_up_date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)"; $rsnotifier = mysql_query($query_notifier, $db); if (!$rsnotifier) { echo "Could not sucessfully run query ($query_notifier) from DB: ". mysql_error(); exit; } if (mysql_num_rows($rsnotifier) == 0) { echo "no rows found, nothing to print so am exiting"; exit; } while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier)) { $email_address = $row_rsnotifier['email_address']; $subject = 'Appointment Reminder'; $message = "<html> <head> <title>Calendar Appointment</title> </head> <body style='background-image:url(http://www.images/bkrnd.jpg); background-repeat:no-repeat; background-position:center;'> <p></p> <p></p> <p></p> <p></p> Hello, $row_rsnotifier[username] <br /> <h3>This is a friendly reminder from XYZ:</h3><br/>"; do{ if ($row_rsnotifier[nick_name] != '') $message .= "$row_rsnotifier[nick_name] is due on $row_rsnotifier[hmfollow_up_date] <hr color='#FFCE00' size='1'><br />"; } while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier)); $message .='<p></p> </body> </html>'; } mysql_free_result($rsnotifier); $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'From: [email protected]'; mail($email_address++, $subject, $message, $headers); </code> Thank you to all in advance! Quote Link to comment https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/ Share on other sites More sharing options...
joePHP Posted June 23, 2010 Share Posted June 23, 2010 Hi, Put the mail function in your while loop while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier)) { $email_address = $row_rsnotifier['email_address']; $subject = 'Appointment Reminder'; $message = "<html> <head> <title>Calendar Appointment</title> </head> <body style='background-image:url(http://www.images/bkrnd.jpg); background-repeat:no-repeat; background-position:center;'> <p></p> <p></p> <p></p> <p></p> Hello, $row_rsnotifier[username] <br /> <h3>This is a friendly reminder from XYZ:</h3><br/>"; do{ if ($row_rsnotifier[nick_name] != '') $message .= "$row_rsnotifier[nick_name] is due on $row_rsnotifier[hmfollow_up_date] <hr color='#FFCE00' size='1'><br />"; } while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier)); $message .='<p></p> </body> </html>'; $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'From: [email protected]'; mail($email_address, $subject, $message, $headers); } Like this it sends an email to the current customer it just received from the database. Quote Link to comment https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/#findComment-1075886 Share on other sites More sharing options...
Silver Mountain Posted June 23, 2010 Author Share Posted June 23, 2010 Yep... I wrapped it with the "while..." statement and it sent an email to the last person in the query with everyones appointment in the database, so I removed the do{ if ($row_rsnotifier[nick_name] != '') $message .= "$row_rsnotifier[nick_name] is due on $row_rsnotifier[hmfollow_up_date] <hr color='#FFCE00' size='1'><br />"; } while ($row_rsnotifier = mysql_fetch_assoc($rsnotifier)); from $message, and ran the script again at which point an email was sent for each appointment in the database. Which is good, but two of the appointments were tied to one email address, which meant the customer received two emails about two different appointments. I need to determine how to capture all appointments from the database and then break them out based off of the customers email and populate an html email message and send one email for each address that has an upcoming appointment be it one or many appointments. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/#findComment-1075915 Share on other sites More sharing options...
Silver Mountain Posted June 23, 2010 Author Share Posted June 23, 2010 I'm thinking "foreach" construct might be what I'm looking for. Feeding the brain cells right now. More to come..... Quote Link to comment https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/#findComment-1075937 Share on other sites More sharing options...
Ruzzas Posted June 23, 2010 Share Posted June 23, 2010 foreach would be a good one but you could use while. But I recommend foreach Quote Link to comment https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/#findComment-1075938 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.