0
votes

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   = "[email protected]"; // SMTP account username
$mail->Password   = "mypasss";        // SMTP account password

$mail->SetFrom('[email protected]', 'myserver Support');

$mail->AddReplyTo("[email protected]","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 = "[email protected]";
$mail->AddAddress($address, "[email protected]");


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
I'm pretty sure it's actually built into the email protocol that you can't detect which are successful. Otherwise, this information could be used maliciously to discover email addresses for spamming purposes.Sildoreth
@Sildoreth i am not trying to find which hit the mailbox, i am just trying to find which i have sent successfully, in case something goes wrong , like timeout in script , big latency and/or SMTP server closes connection, or kicks me out or limits the BCC count.user1642018

1 Answers

1
votes

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.