SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    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:
    $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);
    }
    Any suggestions?

    Thanks

  2. #2
    SitePoint Evangelist
    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);


  3. #3
    SitePoint Addict
    Join Date
    Sep 2001
    Location
    St. Louis, MO
    Posts
    212
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Andy, works perfect. So obvious now that you told me. Much appreciated!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •