I see a lot of PHP email implementations using "\r\n", but I have also seen some of them using the PHP_EOL constant. Which one is better?
Thanks for any help
Metropolis
If this is to terminate lines in an email then it's the spec for email that you need to look at, not what is used on any particular platform.
Lines in email are terminated by CRLF ("\r\n") according to RFC2821
SMTP commands and, unless altered by a service extension, message data, are transmitted in "lines". Lines consist of zero or more data characters terminated by the sequence ASCII character "CR" (hex value 0D) followed immediately by ASCII character "LF" (hex value 0A). This termination sequence is denoted as in this document. Conforming implementations MUST NOT recognize or generate any other character or character sequence as a line terminator
That seems pretty clear that in an email the end of line is to be sent as \r\n . Sending anything else might work but it's wrong unless you are using a "service extension" and if you are then you probably know what you should be sending anyway.
Just to make sure:
PHP_EOL
will have no effect on the email at the receiver side. It will use the new line character combination that is common on the system your PHP script is running on.
So if you have a Linux/Unix server, PHP_EOL
will result in \n
and if you have a Windows server, it will be \r\n
.
Today, it should not matter that much which you use and I think that most Windows email applications can also handle just \n
(afaik even WordPad understands this, it is Notepad that has problems).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With