diff --git a/README.md b/README.md index eebc073e..244e7e1c 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Build status: [](h [](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/) [](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/) +[](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) [](https://packagist.org/packages/phpmailer/phpmailer) + ## Class Features - Probably the world's most popular code for sending email from PHP! diff --git a/changelog.md b/changelog.md index a467c5d9..1ed9f3af 100644 --- a/changelog.md +++ b/changelog.md @@ -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** diff --git a/class.phpmailer.php b/class.phpmailer.php index 38ff3a6b..245e9bad 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -467,7 +467,7 @@ class PHPMailer /** * An array of all kinds of addresses. - * Includes all of $to, $cc, $bcc, $replyto + * Includes all of $to, $cc, $bcc * @type array * @access protected */ @@ -1248,32 +1248,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 @@ -1288,8 +1273,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 ); } @@ -3449,8 +3438,8 @@ class PHPMailer $to_header = $header; $current = 'to_header'; } else { - if ($current && strpos($header, ' =?') === 0) { - $current .= $header; + if (!empty($$current) && strpos($header, ' =?') === 0) { + $$current .= $header; } else { $current = ''; } diff --git a/class.pop3.php b/class.pop3.php index 984885ff..fe121a1e 100644 --- a/class.pop3.php +++ b/class.pop3.php @@ -130,8 +130,8 @@ class POP3 /** * Simple static wrapper for all-in-one POP before SMTP * @param $host - * @param boolean $port - * @param boolean $tval + * @param integer|boolean $port The port number to connect to + * @param integer|boolean $timeout The timeout value * @param string $username * @param string $password * @param integer $debug_level @@ -140,13 +140,13 @@ class POP3 public static function popBeforeSmtp( $host, $port = false, - $tval = false, + $timeout = false, $username = '', $password = '', $debug_level = 0 ) { $pop = new POP3; - return $pop->authorise($host, $port, $tval, $username, $password, $debug_level); + return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level); } /** diff --git a/class.smtp.php b/class.smtp.php index 8c609d72..81a85d08 100644 --- a/class.smtp.php +++ b/class.smtp.php @@ -631,7 +631,7 @@ class SMTP if ($in_headers and $line == '') { $in_headers = false; } - //We need to break this line up into several smaller lines + //Break this line up into several smaller lines if it's too long //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len), while (isset($line[self::MAX_LINE_LENGTH])) { //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on diff --git a/examples/contents.html b/examples/contents.html index 9257f6dd..dc3fc667 100644 --- a/examples/contents.html +++ b/examples/contents.html @@ -1,17 +1,17 @@
- +This example uses HTML.
-The PHPMailer image at the top has been embedded automatically.
+ diff --git a/examples/contentsutf8.html b/examples/contentsutf8.html new file mode 100644 index 00000000..81a20240 --- /dev/null +++ b/examples/contentsutf8.html @@ -0,0 +1,20 @@ + + + + +This example uses HTML.
+Chinese text: 郵件內容為空
+Russian text: Пустое тело сообщения
+Armenian text: Հաղորդագրությունը դատարկ է
+Czech text: Prázdné tělo zprávy
+Chinese text: 郵件內容為空
+Russian text: Пустое тело сообщения
+Armenian text: Հաղորդագրությունը դատարկ է
+Czech text: Prázdné tělo zprávy
+ Embedded Image: