Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/205600-email-notifier-wcron/
Share on other sites

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.

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.