SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Dec 2005
    Posts
    964
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    phpmailer doesn't make sense?!?!?

    I' using phpmailer to send out newsletters and that allmost works greate but one problem. I want individuel names in my emails and I get that if I do as my script below, but the second reciever recieves an email with the same content twice, like a duplicate of the email sent to the first reciever and the third reciever gets duplicates of the first and the second and so on...

    Here is what i have so far:
    PHP Code:
    include_once('class.phpmailer.php');

    $mail = new PHPMailer();

    $mail->Host       "mail.mypage.com"// SMTP server
    $mail->IsSendmail(); // telling the class to use SendMail transport

    $mail->From       'me@mypage.com';
    $mail->FromName   'My Name';

    $sql="SELECT * FROM ".$prefix."_table WHERE newsletter=1";
    $result mysql_query($sql);
    while(
    $row mysql_fetch_array($result)){
        
        
    $mail->Subject "This is a test";
        
        
    $textHTML "Hello ".$row['name'].",<br><br>";
        
    $textHTML .= "This is an test message... Just testing!";
        
        
    $body $textHTML;
        
        
    $mail->AltBody .= "To view the message, please use an HTML compatible email viewer!";
        
        
    $mail->AddAddress($row['email'], $row['name']);
        
        
    $body eregi_replace("[\]",'',$body);
        
        
    $mail->MsgHTML($body);
        
        if(!
    $mail->Send()) {
          echo 
    "Mailer Error: " $mail->ErrorInfo;
        } else {
          echo 
    'Message sent to: '.$row['email'].'<br>';
        }
        
        
    $mail->ClearAddresses();
        
    $mail->ClearAttachments();
        

    Its tearing me a part so please help...

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,096
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Remove the . (from .=) in this line and you should be fine:

    PHP Code:
    $mail->AltBody .= "To view the message, please use an HTML compatible email viewer!"
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Zealot ChrisWiegman's Avatar
    Join Date
    Sep 2010
    Location
    Austin, Texas, United States
    Posts
    177
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's been a while since I've custom written a mail script but I do believe the issue is in how you're creating $mail. Try creating it in your look and see if that helps.


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
  •