Skip to content

Commit 1a6e402

Browse files
committed
Fixed sending emails for PHP 8 (now mail() always use CRLF (\r\n) no matter what OS is used, no more crutches required).
1 parent 7dd91ac commit 1a6e402

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

_include/comments.php

+18-11
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,15 @@ function s2_mail_comment ($name, $email, $text, $title, $url, $auth_name, $unsub
186186
'Reply-To: '.$from;
187187

188188
// Change the linebreaks used in the headers according to OS
189-
if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC')
190-
$headers = str_replace("\r\n", "\r", $headers);
191-
else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN')
192-
$headers = str_replace("\r\n", "\n", $headers);
193-
189+
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) {
190+
// Change the linebreaks used in the headers according to OS
191+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') {
192+
$headers = str_replace("\r\n", "\r", $headers);
193+
}
194+
else if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
195+
$headers = str_replace("\r\n", "\n", $headers);
196+
}
197+
}
194198
mail($email, $subject, $message, $headers);
195199
}
196200

@@ -226,12 +230,15 @@ function s2_mail_moderator ($name, $email, $text, $title, $url, $auth_name, $aut
226230
'X-Mailer: S2 Mailer'."\r\n".
227231
'Reply-To: '.$from;
228232

229-
// Change the linebreaks used in the headers according to OS
230-
if (strtoupper(substr(PHP_OS, 0, 3)) == 'MAC')
231-
$headers = str_replace("\r\n", "\r", $headers);
232-
else if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN')
233-
$headers = str_replace("\r\n", "\n", $headers);
234-
233+
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80000) {
234+
// Change the linebreaks used in the headers according to OS
235+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') {
236+
$headers = str_replace("\r\n", "\r", $headers);
237+
}
238+
else if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
239+
$headers = str_replace("\r\n", "\n", $headers);
240+
}
241+
}
235242
mail($email, $subject, $message, $headers);
236243
}
237244

0 commit comments

Comments
 (0)