Re: Re[2]: text email & new line

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Richard,

On Wed, 3 Nov 2004 00:19:59 +0000, Richard Davey <rich@xxxxxxxxxxxxxxxx> wrote:
> Hello Jordi,
> 
> Tuesday, November 2, 2004, 5:34:00 PM, you wrote:
> 
> JC> I hope this will help in composing mail messages and my recommendation
> JC> is to *follow the standard* and send messages always by using CRLF as
> JC> a line delimiter. Only doing that way, you will ensure your messages
> JC> are accepted by any server.
> 
> I'm not disagreeing with what you posted, because it's all true, but I
> would like to ask - can you actually name a popular mail server that
> rejects emails that use \n as a line delimiter (even if used by
> mistake), because I've haven't seen it happen for years.
> 

Well, I don't know if this has changed, but less than one year ago
Hotmail was one of them and dropped mail messages with LF as line
separator. Some SMTP implementations on Windows also drops the
messages. And, finally some clients don't wrap the message correctly
when received and you have to scroll horizontally to read long lines.

Take in attention the 2.3.7 section of the RFC 2821 wich says: SMTP
client implementations MUST NOT transmit these characters (CR or LF)
except when they are intended as line terminators and then MUST,
transmit them only as a <CRLF> sequence.

So, when we are sending a message from PHP, we are involved in an SMTP
client implementation. Then, when composing the headers or the body
for a message to be sent (i.e. using the mail() function) we have to
follow the standards to ensure that the message will not be rejected
by any server just because we sent it in a bad format.

So, because we cannot ensure that all SMTP servers in the world will
accept non-standard line terminators, my recommendation when sending
mail, is to use the standard line terminator and compose headers and
body with <CRLF> as a line terminator. Only that way you will be
absolutelly sure that the mail will not be rejected because of line
terminators.

I think a good way to do it, is to define a CRLF constant:

define('CRLF', "\r\n");

You could also ensure that the body is well formed forcing the line
terminators to CRLF:

$body = preg_replace("/(\r\n)|(\r)|(\n)/", "\r\n", $body);

Best regards,
Jordi.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux