diff --git a/phpBB/docs/CHANGELOG.html b/phpBB/docs/CHANGELOG.html
index 7854ba88d5..97390949aa 100644
--- a/phpBB/docs/CHANGELOG.html
+++ b/phpBB/docs/CHANGELOG.html
@@ -113,6 +113,7 @@
[Fix] Fix infinite loop in message handler if cache directory is not writable. (Bug #38675)
[Fix] While post is awaiting approval it can still be edited even though it can not be seen (Bug #41435 - Patch by TerraFrost)
[Fix] Fix imageset editing for retaining and correctly setting dimensions for images, as well as displaying correct settings for first page load.
+ [Fix] Use OS-specific line endings for mail headers. (related to Bug #42755)
[Change] Allow download of conflicting file for later reference in automatic updater
[Change] Default difference view is now 'inline' instead of 'side by side'
[Change] Added new option for merging differences to conflicting files in automatic updater
diff --git a/phpBB/includes/functions_messenger.php b/phpBB/includes/functions_messenger.php
index ba38d6d0f1..14465ef13c 100644
--- a/phpBB/includes/functions_messenger.php
+++ b/phpBB/includes/functions_messenger.php
@@ -28,6 +28,7 @@ class messenger
var $mail_priority = MAIL_NORMAL_PRIORITY;
var $use_queue = true;
var $tpl_msg = array();
+ var $eol = "\n";
/**
* Constructor
@@ -38,6 +39,9 @@ class messenger
$this->use_queue = (!$config['email_package_size']) ? false : $use_queue;
$this->subject = '';
+
+ // Determine EOL character (\n for UNIX, \r\n for Windows and \r for Mac)
+ $this->eol = (!defined('PHP_EOL')) ? (($eol = strtolower(substr(PHP_OS, 0, 3))) == 'win') ? "\r\n" : (($eol == 'mac') ? "\r" : "\n") : PHP_EOL;
}
/**
@@ -309,6 +313,7 @@ class messenger
{
global $config;
+ // We could use keys here, but we won't do this for 3.0.x to retain backwards compatibility
$headers = array();
$headers[] = 'From: ' . $this->from;
@@ -338,15 +343,12 @@ class messenger
$headers[] = 'X-MimeOLE: phpBB3';
$headers[] = 'X-phpBB-Origin: phpbb://' . str_replace(array('http://', 'https://'), array('', ''), generate_board_url());
- // We use \n here instead of \r\n because our smtp mailer is adjusting it to \r\n automatically, whereby the php mail function only works
- // if using \n.
-
if (sizeof($this->extra_headers))
{
- $headers[] = implode("\n", $this->extra_headers);
+ $headers = array_merge($headers, $this->extra_headers);
}
- return implode("\n", $headers);
+ return $headers;
}
/**
@@ -412,6 +414,10 @@ class messenger
}
else
{
+ // We use the EOL character for the OS here because the PHP mail function does not correctly transform line endings. On Windows SMTP is used (SMTP is \r\n), on UNIX a command is used...
+ // Reference: http://bugs.php.net/bug.php?id=15841
+ $headers = implode($this->eol, $headers);
+
ob_start();
$result = $config['email_function_name']($mail_to, mail_encode($this->subject), wordwrap(utf8_wordwrap($this->msg), 997, "\n", true), $headers);
$err_msg = ob_get_clean();
@@ -652,7 +658,7 @@ class queue
else
{
ob_start();
- $result = $config['email_function_name']($to, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);
+ $result = $config['email_function_name']($to, mail_encode($subject), wordwrap(utf8_wordwrap($msg), 997, "\n", true), implode($this->eol, $headers));
$err_msg = ob_get_clean();
}
@@ -757,40 +763,37 @@ class queue
/**
* Replacement or substitute for PHP's mail command
*/
-function smtpmail($addresses, $subject, $message, &$err_msg, $headers = '')
+function smtpmail($addresses, $subject, $message, &$err_msg, $headers = false)
{
global $config, $user;
// Fix any bare linefeeds in the message to make it RFC821 Compliant.
$message = preg_replace("#(? 1) ? join("\n", $headers) : $headers[0];
+ // Make sure there are no bare linefeeds in the headers
+ $headers = preg_replace('#(?server_send("$headers\r\n");
+ if ($headers !== false)
+ {
+ $smtp->server_send("$headers\r\n");
+ }
// Ok now we are ready for the message...
$smtp->server_send($message);