From 1a6e402ce4a128b30b444658c8a3e2ed907c9d4d Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Thu, 24 Aug 2023 19:24:43 +0300 Subject: [PATCH] Fixed sending emails for PHP 8 (now mail() always use CRLF (\r\n) no matter what OS is used, no more crutches required). --- _include/comments.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/_include/comments.php b/_include/comments.php index 2ffd6f1a..4536803e 100644 --- a/_include/comments.php +++ b/_include/comments.php @@ -186,11 +186,15 @@ function s2_mail_comment ($name, $email, $text, $title, $url, $auth_name, $unsub 'Reply-To: '.$from; // Change the linebreaks used in the headers according to OS - if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC') - $headers = str_replace("\r\n", "\r", $headers); - else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') - $headers = str_replace("\r\n", "\n", $headers); - + if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) { + // Change the linebreaks used in the headers according to OS + if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') { + $headers = str_replace("\r\n", "\r", $headers); + } + else if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $headers = str_replace("\r\n", "\n", $headers); + } + } mail($email, $subject, $message, $headers); } @@ -226,12 +230,15 @@ function s2_mail_moderator ($name, $email, $text, $title, $url, $auth_name, $aut 'X-Mailer: S2 Mailer'."\r\n". 'Reply-To: '.$from; - // Change the linebreaks used in the headers according to OS - if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC') - $headers = str_replace("\r\n", "\r", $headers); - else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') - $headers = str_replace("\r\n", "\n", $headers); - + if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) { + // Change the linebreaks used in the headers according to OS + if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') { + $headers = str_replace("\r\n", "\r", $headers); + } + else if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { + $headers = str_replace("\r\n", "\n", $headers); + } + } mail($email, $subject, $message, $headers); }