Skip to content

Commit

Permalink
Generate a warning when using a buggy PHP version, see PHPMailer#953
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Feb 28, 2017
1 parent 24b4351 commit 9c3ba23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This is a major update that breaks backwards compatibility.
* All uses of `PHPMailer::$LE` property converted to use `static::$LE` constant for consistency and ease of overriding
* Similar changes to line break handling in SMTP and POP3 classes.
* Line break format for `mail()` transport is set automatically.
* Warnings emitted in debug output for buggy `mail()` in PHP versions 7.0.0 - 7.0.16 and 7.1.0 - 7.1.2; either upgrade or switch to SMTP.
* Extensive reworking of XOAUTH2, adding support for Google, Yahoo and Microsoft providers, thanks to @sherryl4george
* Major cleanup of docs and examples
* All elements previously marked as deprecated have been removed:
Expand Down
16 changes: 16 additions & 0 deletions src/PHPMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,22 @@ public function preSend()
//Maintain backward compatibility with legacy Linux command line mailers
static::setLE(PHP_EOL);
}
//Check for buggy PHP versions that add a header with an incorrect line break
if (ini_get('mail.add_x_header') == 1
and 'mail' == $this->Mailer
and stripos(PHP_OS, 'WIN') === 0
and ((version_compare(PHP_VERSION, '7.0.0', '>=')
and version_compare(PHP_VERSION, '7.0.17', '<'))
or (version_compare(PHP_VERSION, '7.1.0', '>=')
and version_compare(PHP_VERSION, '7.1.3', '<')))
) {
trigger_error(
'Your version of PHP is affected by a bug that may result in corrupted messages.' .
' To fix it, switch to sending using SMTP, disable the mail.add_x_header option in' .
' your php.ini, switch to MacOS or Linux, or upgrade your PHP to version 7.0.17+ or 7.1.3+.',
E_USER_WARNING
);
}

try {
$this->error_count = 0; // Reset errors
Expand Down

0 comments on commit 9c3ba23

Please sign in to comment.