我是新來使用的PHPMailer發送郵件批量。 如果send()失敗,則執行停止並顯示錯誤。腓梅勒 - 繼續下一個郵件發送,如果()時發生錯誤
有沒有辦法跳過錯誤並繼續下一個電子郵件ID。 我正在使用數據庫中的電子郵件ID。
我是新來使用的PHPMailer發送郵件批量。 如果send()失敗,則執行停止並顯示錯誤。腓梅勒 - 繼續下一個郵件發送,如果()時發生錯誤
有沒有辦法跳過錯誤並繼續下一個電子郵件ID。 我正在使用數據庫中的電子郵件ID。
你可以捕捉異常機制,繼續與下一個郵件與發佈者Phil PHPMailer的適當的邏輯
使用了異常。嘗試採取以下
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('[email protected]', 'First Last');
$mail->AddAddress('[email protected]', 'John Doe');
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo('[email protected]', '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!
}
使用可以使用phplist
爲批量郵寄用PHP郵件或不 click Here更多
在PHP中,您可以通過添加@的功能抑制錯誤顯示。這通常會防止顯示錯誤。
對於你的情況,你可以把代碼在try..catch。在抓部分,檢查是否所有的電子郵件已經發送;如果不是,繼續下一個。這也意味着您需要一種方式來跟蹤總郵件數量和完成的電子郵件數量。
希望這有助於。
謝謝你,它嘗試捕捉工作。 – Sandeep