SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Oct 5, 2003, 12:22 #1
- Join Date
- Sep 2001
- Location
- St. Louis, MO
- Posts
- 212
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
when sending multiple emails, message is repeated
I have a simple db table named 'mail' which has a mailid, email, fname, and lname. I am running a query to pull the mailid and email and then am looping through the result set mailing each one. It sends the emails fine but the link in the body of the message that allows the recipient to remove themselves from the database is repeating itself in every message. For example, there are 4 people in the db. Every mail sent out contains 4 messages saying 'You have received this message because you have visited our site....blah, blah.' and each one is pointing to a differnt mailid.
I've stripped out the relevant code below.
PHP:Any suggestions?
$sender_email = 'Karen's Site';
$header = "From: \"".$sender_email."\" <".$sender_email.">\n";
$header .= "Reply-To: ".$sender_email."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: text/html; charset=iso-8859-1\n";
$header .= "X-Priority: 3\n";
$sql = "select mailid, email from mail";
$res = mysql_query($sql);
while($myrow = mysql_fetch_array($res))
{
$email_addr = $myrow['email'];
$id = $myrow['mailid'];
$message .= "<p><br><font face=arial size=1>You have received this message because you have visited our site\n";
$message .= "If you feel this is a mistake or would just like to unsubscribe,\n";
$message .= "please <a href=""\"http://mysite.com/unsub.php?mailid=" .$id. "&task=delete_mail\">Click Here</a></font>\n";
mail("$email_addr", "$subject", $message, $header);
}
Thanks
-
Oct 5, 2003, 14:34 #2
- Join Date
- Jul 2001
- Location
- Michigan, USA
- Posts
- 414
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You append to the $message in the loop without clearing it everytime. Adjust your while loop to the following:
PHP Code:while($myrow = mysql_fetch_array($res))
{
$message = '';
$email_addr = $myrow['email'];
$id = $myrow['mailid'];
$message .= "<p><br><font face=arial size=1>You have received this message because you have visited our site\n";
$message .= "If you feel this is a mistake or would just like to unsubscribe,\n";
$message .= "please <a href=""\"[url=http://mysite.com/unsub.php?mailid]http://mysite.com/unsub.php?mailid[/url]=" .$id. "&task=delete_mail\">Click Here</a></font>\n";
mail("$email_addr", "$subject", $message, $header);
}
-
Oct 5, 2003, 16:11 #3
- Join Date
- Sep 2001
- Location
- St. Louis, MO
- Posts
- 212
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Bookmarks