PHPMailer Mass mailing using BCC and catching not successfull email addressses

纵饮孤独 提交于 2019-12-18 07:24:44

问题


I am trying to send NewsLetter to 1500 users using PHPMailer and my SMTP servers.

I have tried sending the mails to 2 BCC emails for test, and it sucessfully sent mails. But before I go ahead and send the mail to 1500 email address, I have few questions.

I am using this code snippet.

<?php

require "../PHPMailer-master/PHPMailerAutoload.php";

$bcc_list = array('emailaddrs1,emailaddress2');

$mail             = new PHPMailer();

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.myserver.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "smtp.myserver.com"; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "mailer@myserver.com"; // SMTP account username
$mail->Password   = "mypasss";        // SMTP account password

$mail->SetFrom('mailer@myserver.com', 'myserver Support');

$mail->AddReplyTo("mailer@myserver.com","myserver Support");

$mail->Subject    = "Email sent from xampp";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "support@myserver.com";
$mail->AddAddress($address, "support@myserver.com");


foreach($bcc_list as $bcc_email){
   $mail->AddBCC($bcc_email);
}

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
 //insert that emaill address into database for re-emailing.
} else {
  echo "Message sent!";
}

1) How can i make , the email show users email address in <To> field and not my dummy address ?

2) Does it send as 1 email or 1500 emails ? i.e., how can I catch which emails are successfully sent and which arent ( because of some timeout or something goes wrong) so I can send them again, and not have to spam the all others?


回答1:


In your code you are sending one message to 1 address and BCCing to all the others, so there is only a single To address - this is just how BCC works. If you want to have each recipient's address shown as the To address, you must send each message individually - look at the mailing list example provided. If you want to spot failures in a long list of recipients of any kind, make sure you're using an up-to-date version of PHPMailer as that was buggy in the past. Any bad addresses will be reported in $mail->ErrorInfo.



来源:https://stackoverflow.com/questions/29001389/phpmailer-mass-mailing-using-bcc-and-catching-not-successfull-email-addressses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!