0

I am new to use phpmailer for sending bulk mails. The execution stops and shows error if send() fails.

Is there any way to skip the error and continue with next email id. I am using email id's from database.

4

3 回答 3

0

You Can Catch Exception Mechanism, to continue with next Mail with appropriate logic

Posted by Phil PHPMAiler uses Exceptions. Try to adopt the following

require_once '../class.phpmailer.php';

$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch

try {
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->AddAddress('whoto@otherdomain.com', 'John Doe');
  $mail->SetFrom('name@yourdomain.com', 'First Last');
  $mail->AddReplyTo('name@yourdomain.com', 'First Last');
  $mail->Subject = 'PHPMailer Test Subject via mail(), advanced';
  $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically
  $mail->MsgHTML(file_get_contents('contents.html'));
  $mail->AddAttachment('images/phpmailer.gif');      // attachment
  $mail->AddAttachment('images/phpmailer_mini.gif'); // attachment
  $mail->Send();
  echo "Message Sent OK\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
于 2013-07-19T07:39:00.217 回答
0

use can use phplist for bulk mailing with PHP mailer or without click Here for more

于 2013-07-19T07:46:12.997 回答
0

In PHP, you can suppress error display by adding @ to the function. This will usually prevent the error from being displayed.
For your situation, you can put the code in try..catch. In the catch section, check if the all the emails have been sent; if not, just continue with the next one. This also means that you need a way to track the total emails and the number of emails completed.

Hope this helps.

于 2013-07-19T08:14:54.680 回答