<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hi Adam,<br>
<br>
Well spotted and well diagnosed!<br>
<br>
I didn't think anyone still used the non-PHPMailer email code any
more (it's just left there as it wasn't doing any harm and meant
people weren't forced into any reconfiguration of existing old
servers).<br>
But clearly I woz rong! :-)<br>
<br>
I'll take a look at this and get it fixed for you.<br>
<br>
BTW why still using the inbuilt php mail() function rather than
PHPMailer?<br>
<br>
Cheers,<br>
Jules.<br>
<br>
<div class="moz-cite-prefix">On 11/11/2022 18:07, Adam Thorn via
ZendTo wrote:<br>
</div>
<blockquote type="cite"
cite="mid:WM!7259b246df45549201559d1d961622d5cc42cae69aec08fa3c39695d1c9bd5b8f155c60fa4b75f0cc828da08fc627195!@mx.jul.es">I'm
working on deploying ZendTo to a new Ubuntu 22.04 server. My
current ZendTo instance is on Ubuntu 18.04: in both cases I'm
using the stock Ubuntu-provided PHP packages, so am moving from
PHP 7.4 to PHP 8.1. I'm also moving from ZendTo 5.17-6 to 6.13-2
but I don't think that change is too relevant, as the bug I've
spotted is in code which is identical between those ZendTo
versions.
<br>
<br>
The specific problem I've spotted is in NSSDropbox.php : there may
be similar problems elsewhere. I don't use phpmailer so am looking
at the code path through deliverEmail() which ends in a call to
PHP's mail() function.
<br>
<br>
On the older PHP7.4 server, when I make a dropoff which in turn
sends a mail, everything about the mail is fine, and when I view
the mail headers in Thunderbird I see e.g.
<br>
<br>
From: ZendTo Service <a class="moz-txt-link-rfc2396E" href="mailto:no-reply@cam.ac.uk"><no-reply@cam.ac.uk></a>
<br>
Reply-to: <a class="moz-txt-link-abbreviated" href="mailto:alt36@cam.ac.uk">alt36@cam.ac.uk</a>
<br>
Content-Type: text/plain; charset=UTF-8; format=flowed
<br>
Content-Transfer-Encoding: 8bit
<br>
<br>
However, making a similar dropoff on PHP8.1 the equivalent header
lines read...
<br>
<br>
From: ZendTo Service <a class="moz-txt-link-rfc2396E" href="mailto:no-reply@cam.ac.uk"><no-reply@cam.ac.uk></a>
<br>
Reply-to: <a class="moz-txt-link-abbreviated" href="mailto:alt36@cam.ac.uk">alt36@cam.ac.uk</a>
<br>
Content-Type: text/plain; charset=UTF-8; format=flowed
<br>
Content-Transfer-Encoding: 8bit
<br>
<br>
i.e. there's an extra leading space on the lines after From: which
are generated within deliverEmail(). This is invalid, and leads to
my mail client displaying a mangled From: which is the
concatenation of the above four lines, and with no Reply-To set
(and presumably ignoring Content-Type etc as well)
<br>
<br>
I note the same code block would also generate the bcc: header
lines if needed, so I suspect this bug would also lead to the bcc:
recipients being ignored, but I haven't experimented there.
<br>
<br>
My minimal demo of the problem, and then also what I believe is
the fix, is....
<br>
<br>
# begin demo, following the code used in deliverEmail()
<br>
<br>
$headers = '';
<br>
<br>
$to = '<a class="moz-txt-link-abbreviated" href="mailto:alt36@cam.ac.uk">alt36@cam.ac.uk</a>';
<br>
$sender = '<a class="moz-txt-link-abbreviated" href="mailto:no-reply@example.com">no-reply@example.com</a>';
<br>
<br>
$subject = 'Test subject';
<br>
$content = 'This is a test email';
<br>
<br>
$fromAddr = '<a class="moz-txt-link-abbreviated" href="mailto:sender@example.com">sender@example.com</a>';
<br>
<br>
$headers = sprintf("From: %s", $sender) . PHP_EOL .
<br>
sprintf("Reply-to: %s", $fromAddr) . PHP_EOL . $headers;
<br>
$headers .= "MIME-Version: 1.0".PHP_EOL;
<br>
$headers .= "Content-Type: text/plain; charset=UTF-8;
format=flowed".PHP_EOL;
<br>
$headers .= "Content-Transfer-Encoding: 8bit".PHP_EOL;
<br>
<br>
mail($to, $subject, $content, $headers);
<br>
<br>
# end demo
<br>
<br>
The problem is the use of PHP_EOL, which of course on my Ubuntu
system is the LF character. However, the PHP docs
<a class="moz-txt-link-freetext" href="https://www.php.net/manual/en/function.mail.php">https://www.php.net/manual/en/function.mail.php</a> state that the
$headers need to be separated by CRLF. The use of CRLF is also
specified e.g. in RFC 2822.
<br>
<br>
If I replace the PHP_EOL uses in my example above with literal
"\r\n" strings, the unwanted leading spaces in the headers of the
sent mail disappear and my mail client displays everything as I'd
expect.
<br>
<br>
Given the above, I speculate that there's been a change in the
behaviour of mail() between the PHP versions but haven't gone
searching through changelogs. I also haven't attempted to
understand why the use of just PHP_EOL leads to those extra
leading spaces appearing - that may just be an artefact of how my
mail client ends up displaying a string with embedded LF
characters when it's expecting CRLF, though. And, I've not looked
more widely to see if there are other places in ZendTo with the
same issue.
<br>
<br>
Regards,
<br>
<br>
Adam
<br>
<br>
_______________________________________________
<br>
ZendTo mailing list
<br>
<a class="moz-txt-link-abbreviated" href="mailto:ZendTo@zend.to">ZendTo@zend.to</a>
<br>
<a class="moz-txt-link-freetext" href="http://jul.es/mailman/listinfo/zendto">http://jul.es/mailman/listinfo/zendto</a>
<br>
</blockquote>
<br>
<pre class="moz-signature" cols="72">Jules
--
Julian Field MEng CEng CITP MBCS MIEEE MACM
'It's okay to live without all the answers' - Charlie Eppes, 2011
<a class="moz-txt-link-abbreviated" href="http://www.Zend.To">www.Zend.To</a>
Twitter: @JulesFM
</pre>
</body>
</html>