0
0
mirror of https://github.com/PHPMailer/PHPMailer.git synced 2024-09-20 01:52:15 +02:00

Provide detailed errors when sending to individual recipients fails

This commit is contained in:
Synchro 2015-03-25 11:05:42 +01:00
parent 95bd39a094
commit 947415c73a
2 changed files with 16 additions and 26 deletions

View File

@ -24,6 +24,7 @@
* Improved checks and error messages for missing extensions
* Store and report SMTP errors more consistently
* Add MIME multipart preamble for better Outlook compatibility
* Provide detailed errors when individual recipients fail
## Version 5.2.9 (Sept 25th 2014)
* **Important: The autoloader is no longer autoloaded by the PHPMailer class**

View File

@ -1234,32 +1234,17 @@ class PHPMailer
}
// Attempt to send to all recipients
foreach ($this->to as $to) {
if (!$this->smtp->recipient($to[0])) {
$bad_rcpt[] = $to[0];
$isSent = false;
} else {
$isSent = true;
foreach (array($this->to, $this->cc, $this->bcc) as $togroup) {
foreach ($togroup as $to) {
if (!$this->smtp->recipient($to[0])) {
$error = $this->smtp->getError();
$bad_rcpt[] = array('to' => $to[0], 'error' => $error['detail']);
$isSent = false;
} else {
$isSent = true;
}
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
}
$this->doCallback($isSent, array($to[0]), array(), array(), $this->Subject, $body, $this->From);
}
foreach ($this->cc as $cc) {
if (!$this->smtp->recipient($cc[0])) {
$bad_rcpt[] = $cc[0];
$isSent = false;
} else {
$isSent = true;
}
$this->doCallback($isSent, array(), array($cc[0]), array(), $this->Subject, $body, $this->From);
}
foreach ($this->bcc as $bcc) {
if (!$this->smtp->recipient($bcc[0])) {
$bad_rcpt[] = $bcc[0];
$isSent = false;
} else {
$isSent = true;
}
$this->doCallback($isSent, array(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
}
// Only send the DATA command if we have viable recipients
@ -1274,8 +1259,12 @@ class PHPMailer
}
//Create error message for any bad addresses
if (count($bad_rcpt) > 0) {
$errstr = '';
foreach ($bad_rcpt as $bad) {
$errstr .= $bad['to'] . ': ' . $bad['error'];
}
throw new phpmailerException(
$this->lang('recipients_failed') . implode(', ', $bad_rcpt),
$this->lang('recipients_failed') . $errstr,
self::STOP_CONTINUE
);
}