Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into autotls
Browse files Browse the repository at this point in the history
# Conflicts:
#	changelog.md
  • Loading branch information
Synchro committed Apr 17, 2015
2 parents 07176c0 + 245d73b commit e427427
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 48 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -6,6 +6,8 @@ Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](h
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/badges/quality-score.png?s=3758e21d279becdf847a557a56a3ed16dfec9d5d)](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/badges/coverage.png?s=3fe6ca5fe8cd2cdf96285756e42932f7ca256962)](https://scrutinizer-ci.com/g/PHPMailer/PHPMailer/)

[![Latest Stable Version](https://poser.pugx.org/phpmailer/phpmailer/v/stable.svg)](https://packagist.org/packages/phpmailer/phpmailer) [![Total Downloads](https://poser.pugx.org/phpmailer/phpmailer/downloads.svg)](https://packagist.org/packages/phpmailer/phpmailer) [![Latest Unstable Version](https://poser.pugx.org/phpmailer/phpmailer/v/unstable.svg)](https://packagist.org/packages/phpmailer/phpmailer) [![License](https://poser.pugx.org/phpmailer/phpmailer/license.svg)](https://packagist.org/packages/phpmailer/phpmailer)

## Class Features

- Probably the world's most popular code for sending email from PHP!
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -25,6 +25,8 @@
* Store and report SMTP errors more consistently
* Add MIME multipart preamble for better Outlook compatibility
* Enable TLS encryption automatically if the server offers it
* Provide detailed errors when individual recipients fail
* Report more errors when connecting

## Version 5.2.9 (Sept 25th 2014)
* **Important: The autoloader is no longer autoloaded by the PHPMailer class**
Expand Down
48 changes: 19 additions & 29 deletions class.phpmailer.php
Expand Up @@ -475,7 +475,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
*/
Expand Down Expand Up @@ -1242,32 +1242,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 @@ -1282,8 +1267,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 Expand Up @@ -1392,6 +1381,7 @@ public function smtpConnect($options = array())
return true;
} catch (phpmailerException $exc) {
$lastexception = $exc;
$this->edebug($exc->getMessage());
// We must have connected, but then failed TLS or Auth, so close connection nicely
$this->smtp->quit();
}
Expand Down Expand Up @@ -3438,8 +3428,8 @@ public function DKIM_Add($headers_line, $subject, $body)
$to_header = $header;
$current = 'to_header';
} else {
if ($current && strpos($header, ' =?') === 0) {
$current .= $header;
if (!empty($$current) && strpos($header, ' =?') === 0) {
$$current .= $header;
} else {
$current = '';
}
Expand Down
8 changes: 4 additions & 4 deletions class.pop3.php
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion class.smtp.php
Expand Up @@ -631,7 +631,7 @@ public function data($msg_data)
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
Expand Down
16 changes: 8 additions & 8 deletions examples/contents.html
@@ -1,17 +1,17 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>PHPMailer Test</title>
</head>
<body>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<h1>This is a test of PHPMailer.</h1>
<div align="center">
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
</div>
<p>This example uses <strong>HTML</strong>.</p>
<p>The PHPMailer image at the top has been embedded automatically.</p>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<h1>This is a test of PHPMailer.</h1>
<div align="center">
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
</div>
<p>This example uses <strong>HTML</strong>.</p>
<p>ISO-8859-1 text: éèîüçÅñæß</p>
</div>
</body>
</html>
20 changes: 20 additions & 0 deletions examples/contentsutf8.html
@@ -0,0 +1,20 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHPMailer Test</title>
</head>
<body>
<div style="width: 640px; font-family: Arial, Helvetica, sans-serif; font-size: 11px;">
<h1>This is a test of PHPMailer.</h1>
<div align="center">
<a href="https://github.com/PHPMailer/PHPMailer/"><img src="images/phpmailer.png" height="90" width="340" alt="PHPMailer rocks"></a>
</div>
<p>This example uses <strong>HTML</strong>.</p>
<p>Chinese text: 郵件內容為空</p>
<p>Russian text: Пустое тело сообщения</p>
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
<p>Czech text: Prázdné tělo zprávy</p>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions language/phpmailer.lang-no.php
Expand Up @@ -4,8 +4,8 @@
* @package PHPMailer
*/

$PHPMAILER_LANG['authenticate'] = 'SMTP Feil: Kunne ikke authentisere.';
$PHPMAILER_LANG['connect_host'] = 'SMTP Feil: Kunne ikke koble til SMTP host.';
$PHPMAILER_LANG['authenticate'] = 'SMTP Feil: Kunne ikke autentisere.';
$PHPMAILER_LANG['connect_host'] = 'SMTP Feil: Kunne ikke koble til SMTP tjener.';
$PHPMAILER_LANG['data_not_accepted'] = 'SMTP Feil: Data ble ikke akseptert.';
$PHPMAILER_LANG['empty_message'] = 'Meldingsinnholdet er tomt';
$PHPMAILER_LANG['encoding'] = 'Ukjent tegnkoding: ';
Expand Down
68 changes: 64 additions & 4 deletions test/phpmailerTest.php
Expand Up @@ -149,7 +149,7 @@ public function buildBody()
$eol = "<br>\r\n";
$bullet_start = '<li>';
$bullet_end = "</li>\r\n";
$list_start = '<ul>\r\n';
$list_start = "<ul>\r\n";
$list_end = "</ul>\r\n";
} else {
$eol = "\r\n";
Expand All @@ -166,6 +166,7 @@ public function buildBody()
$ReportBody .= '---------------------' . $eol;
$ReportBody .= 'phpmailer version: ' . $this->Mail->Version . $eol;
$ReportBody .= 'Content Type: ' . $this->Mail->ContentType . $eol;
$ReportBody .= 'CharSet: ' . $this->Mail->CharSet . $eol;

if (strlen($this->Mail->Host) > 0) {
$ReportBody .= 'Host: ' . $this->Mail->Host . $eol;
Expand Down Expand Up @@ -210,7 +211,7 @@ public function buildBody()
}

// Re-attach the original body
$this->Mail->Body .= $eol . $eol . $ReportBody;
$this->Mail->Body .= $eol . $ReportBody;
}

/**
Expand Down Expand Up @@ -800,6 +801,29 @@ public function testHtml()
$this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers');
}

/**
* Send a message containing ISO-8859-1 text.
*/
public function testHtmlIso8859()
{
$this->Mail->isHTML(false);
$this->Mail->Subject .= ": ISO-8859-1 HTML";
$this->Mail->CharSet = 'iso-8859-1';

//This file is in ISO-8859-1 charset
//Needs to be external because this file is in UTF-8
$content = file_get_contents('../examples/contents.html');
//Make sure it really is in ISO-8859-1!
$this->Mail->Body =
mb_convert_encoding(
$content,
"ISO-8859-1",
mb_detect_encoding($content, "UTF-8, ISO-8859-1, ISO-8859-15", true)
);
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

/**
* Send a message containing multilingual UTF-8 text.
*/
Expand All @@ -812,6 +836,7 @@ public function testHtmlUtf8()
$this->Mail->Body = <<<EOT
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HTML email test</title>
</head>
<body>
Expand All @@ -828,6 +853,41 @@ public function testHtmlUtf8()
$this->assertNotContains("\r\n\r\nMIME-Version:", $msg, 'Incorrect MIME headers');
}

/**
* Send a message containing multilingual UTF-8 text with an embedded image.
*/
public function testUtf8WithEmbeddedImage()
{
$this->Mail->isHTML(true);
$this->Mail->Subject .= ": UTF-8 with embedded image";
$this->Mail->CharSet = 'UTF-8';

$this->Mail->Body = <<<EOT
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>HTML email test</title>
</head>
<body>
<p>Chinese text: 郵件內容為空</p>
<p>Russian text: Пустое тело сообщения</p>
<p>Armenian text: Հաղորդագրությունը դատարկ է</p>
<p>Czech text: Prázdné tělo zprávy</p>
Embedded Image: <img alt="phpmailer" src="cid:my-attach">
</body>
</html>
EOT;
$this->Mail->addEmbeddedImage(
'../examples/images/phpmailer.png',
'my-attach',
'phpmailer.png',
'base64',
'image/png'
);
$this->buildBody();
$this->assertTrue($this->Mail->send(), $this->Mail->ErrorInfo);
}

/**
* Send a message containing multilingual UTF-8 text.
*/
Expand All @@ -854,7 +914,7 @@ public function testPlainUtf8()
*/
public function testMsgHTML()
{
$message = file_get_contents('../examples/contents.html');
$message = file_get_contents('../examples/contentsutf8.html');
$this->Mail->CharSet = 'utf-8';
$this->Mail->Body = '';
$this->Mail->AltBody = '';
Expand Down Expand Up @@ -904,7 +964,7 @@ public function testHTMLAttachment()
public function testEmbeddedImage()
{
$this->Mail->Body = 'Embedded Image: <img alt="phpmailer" src="cid:my-attach">' .
'Here is an image!</a>';
'Here is an image!';
$this->Mail->Subject .= ': Embedded Image';
$this->Mail->isHTML(true);

Expand Down

0 comments on commit e427427

Please sign in to comment.