diff --git a/modules/system/system.mail.inc b/modules/system/system.mail.inc index 16a2be4c308..364cf02007b 100644 --- a/modules/system/system.mail.inc +++ b/modules/system/system.mail.inc @@ -62,7 +62,14 @@ class DefaultMailSystem implements MailSystemInterface { $mail_body = preg_replace('@\r?\n@', $line_endings, $message['body']); // For headers, PHP's API suggests that we use CRLF normally, // but some MTAs incorrectly replace LF with CRLF. See #234403. - $mail_headers = join("\n", $mimeheaders); + $headers_line_endings = variable_get('mail_headers_line_endings', "\n"); + if (defined('PHP_VERSION_ID') && PHP_VERSION_ID >= 80000 ) { + // PHP 8+ requires headers to be separated by CRLF, see: + // - https://bugs.php.net/bug.php?id=81158 + // - https://github.com/php/php-src/commit/6983ae751cd301886c966b84367fc7aaa1273b2d#diff-c6922cd89f6f75912eb377833ca1eddb7dd41de088be821024b8a0e340fed3df + $headers_line_endings = variable_get('mail_headers_line_endings', "\r\n"); + } + $mail_headers = join($headers_line_endings, $mimeheaders); // We suppress warnings and notices from mail() because of issues on some // hosts. The return value of this method will still indicate whether mail