Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should PHP_EOL be used in emails?

Tags:

php

email

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

like image 235
Metropolis Avatar asked Jul 14 '10 16:07

Metropolis


2 Answers

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.

like image 192
jcoder Avatar answered Nov 02 '22 05:11

jcoder


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).

like image 38
Felix Kling Avatar answered Nov 02 '22 07:11

Felix Kling