Skip to content

Commit

Permalink
Merge pull request #344 from fballiano/patch-1
Browse files Browse the repository at this point in the history
Fixed "emails are displayed incorrectly" with PHP 8.1+
  • Loading branch information
develart-projects authored Aug 9, 2023
2 parents 41a26bf + e38751e commit ae9e5df
Showing 1 changed file with 24 additions and 9 deletions.
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

0 comments on commit ae9e5df

Please sign in to comment.