Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed "emails are displayed incorrectly" with PHP 8.1+ #344

Merged
merged 2 commits into from
Aug 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions library/Zend/Mail/Transport/Sendmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Zend_Mail_Transport_Sendmail extends Zend_Mail_Transport_Abstract
* @var string
* @access public
*/
public $EOL = PHP_EOL;
public $EOL = "\r\n";

/**
* error information
Expand Down Expand Up @@ -97,13 +97,25 @@ public function __construct($parameters = null)
*/
public function _sendMail()
{
$recipients = $this->recipients;
$subject = $this->_mail->getSubject();
$body = $this->body;
$header = $this->header;
$isWindowsOs = strtoupper(substr(PHP_OS, 0, 3)) == 'WIN';
if (PHP_VERSION_ID < 80000 && !$isWindowsOs) {
$recipients = str_replace("\r\n", "\n", $recipients);
$subject = str_replace("\r\n", "\n", $subject);
$body = str_replace("\r\n", "\n", $body);
$header = str_replace("\r\n", "\n", $header);
}

if ($this->parameters === null) {
set_error_handler([$this, '_handleMailErrors']);
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header);
$recipients,
$subject,
$body,
$header);
restore_error_handler();
} else {
if(!is_string($this->parameters)) {
Expand All @@ -120,16 +132,19 @@ public function _sendMail()
}

$fromEmailHeader = str_replace(' ', '', $this->parameters);
if (PHP_VERSION_ID < 80000 && !$isWindowsOs) {
$fromEmailHeader = str_replace("\r\n", "\n", $fromEmailHeader);
}
// Sanitize the From header
if (!Zend_Validate::is($fromEmailHeader, 'EmailAddress')) {
throw new Zend_Mail_Transport_Exception('Potential code injection in From header');
} else {
set_error_handler([$this, '_handleMailErrors']);
$result = mail(
$this->recipients,
$this->_mail->getSubject(),
$this->body,
$this->header,
$recipients,
$subject,
$body,
$header,
$fromEmailHeader);
restore_error_handler();
}
Expand Down