Skip to content

Commit

Permalink
Provide detailed errors when sending to individual recipients fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Mar 25, 2015
1 parent 95bd39a commit 947415c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
1 change: 1 addition & 0 deletions changelog.md
Expand Up @@ -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**
Expand Down
41 changes: 15 additions & 26 deletions class.phpmailer.php
Expand Up @@ -1234,32 +1234,17 @@ protected function smtpSend($header, $body)
}

// 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;
}
$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;
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(), array(), array($bcc[0]), $this->Subject, $body, $this->From);
}

// Only send the DATA command if we have viable recipients
Expand All @@ -1274,8 +1259,12 @@ protected function smtpSend($header, $body)
}
//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
);
}
Expand Down

0 comments on commit 947415c

Please sign in to comment.