php mailer

Discussion in 'PHP' started by dourvas, Dec 4, 2009.

  1. #1
    hallo there,

    so here s the deal,

    i use php mailer to send mail to multiple directions.

    i get the mail addresses from a database..

    so here's the code

    
    .
    .
    $title=$_POST['title'];
    $subject=$_POST['title'];
    $author=$_POST['author'];
    $news=$_POST['news'];
    $today= date('Y M d');
    
    $message = $today."\n\name: ".strip_tags(stripslashes($_POST["author"]))."\ntitle: ".strip_tags(stripslashes($_POST["title"]))."\nMessage: ".strip_tags(stripslashes($_POST["news"]))."\n";
    
    require_once("pmailer/class.phpmailer.php");
       
       $mail = new PHPMailer();
    
       $mail -> IsSMTP();
    
       $mail -> Host = "websitemail";
        
       $mail->Mailer   = "smtp";
    
       $mail -> Username = "name";
    
       $mail -> Password = "psw";
       
       $mail->SMTPAuth  =  "true";
    
       $mail -> From = "	iekkozan@sch.gr";
    
       $mail -> FromName = "I.E.K ÊÏÆÁÍÇÓ";
    
    $query=mysql_query("SELECT mail FROM members WHERE mail != ''");
    while ($m=mysql_fetch_array($query))
    {
              $maddress=$m[mail];
    
     $mail -> AddAddress($maddress, "IEK KOZANIS");
    
     $mail -> CharSet = "ISO-8859-7";
    
     $mail -> Subject = $subject;
    
     $mail -> Body = $message;
    
    
    if($mail->Send())
    
    {
    
      // echo "";
    
      exit;
    
    }
    
    else 
    {
     //echo "";
    exit;
     }
    }
    
    Code (markup):
    it works! but the mail to each direction arrives 2-3 times!! why? i want just one mail to be sent to each direction. one time.....

    could u help me??
     
    dourvas, Dec 4, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    can u also post the code of pmailer/class.phpmailer.php here
     
    Bohra, Dec 4, 2009 IP
  3. dourvas

    dourvas Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ?
    i just downloaded it and installed it. i did not mess with that class at all.. should i??

    i can not post it because it is too long..... the system doesnt allow me..
     
    dourvas, Dec 4, 2009 IP
  4. frank007

    frank007 Well-Known Member

    Messages:
    160
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    123
    #4
    The mail which you getting 2-3 times contains then same body or different ?
     
    frank007, Dec 4, 2009 IP
  5. dourvas

    dourvas Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i get it 2 times. the second mail is empty
     
    dourvas, Dec 5, 2009 IP
  6. dourvas

    dourvas Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    someone please help me with this.

    i put in my mail list 45 different email addresses and i sent my first newsletter.
    every addressee received the mail 45 times!! total desaster.

    in the previous messages i was testing the service only with 2 addresses in my email table thats why i was receiving the mail only 2 times.

    what should i do??????????
     
    dourvas, Dec 9, 2009 IP
  7. mpchekuri

    mpchekuri Member

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    26
    #7
    Just put a check in the loop to go to next or not till you click yes.
     
    mpchekuri, Dec 9, 2009 IP
  8. dourvas

    dourvas Peon

    Messages:
    31
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    pretty good idea but i just implemented it using another way

    here is the code to send emails to multiple direction. my way...

    
    //connect to database.....done
    
    $query=mysql_query("SELECT email FROM newsletter WHERE email != ''");
    
    while ($m=mysql_fetch_array($query))
    {
              $maddress=$m[email];
    
    require_once("pmailer/class.phpmailer.php");
    
         $mail = new PHPMailer();
    
         $mail -> IsSMTP();
    
         $mail -> Host = "websitemail";
        
         $mail->Mailer   = "smtp";
    
        $mail -> Username = "myusername";
    
       $mail -> Password = "my psw";
       
       $mail->SMTPAuth  =  "true";
    
       $mail -> From = "	iekkozan@sch.gr";
    
       $mail -> FromName = "I.E.K ";
    
      $mail -> AddAddress($maddress, "iek");
    
      $mail -> CharSet = "ISO-8859-7";
    
     $mail -> Subject = $subject;
    
     $mail -> Body = $message;
    
    if($mail->Send())
    
    {
    
       echo "ok";
    
    
    }
    
    else 
    {
     echo "not ok";
    
     }
    }
    
    
    Code (markup):
    maybe not the best way but it works,,,,
     
    dourvas, Dec 9, 2009 IP