Jump to content

Email function: /n same as CRLF?


kurt.santo

Recommended Posts

I had problems with sending an activation code email to Yahoo and found the reason to be I used "/n/n". With the line reading now:$body = "Thank you for registering. To activate your account, please click on this link:\n";the email arrives at my Yahoo email account. My main objective is achieved. Still...But I do not really get it: Many people advice on the net "I suggest you try using only \n, stick with the standards and use CRLF instead of only \n (RFC1425, RFC822)". What does this mean? I am not cynical or sth, I just do not understand. Is /n the same as CRLF?Kurt

Link to comment
Share on other sites

/n is nothing (or rather, they are two characters that resolve to "/n").\n is the "line feed" control character. However, there is also the "carriage return" control character, \r, and CRLF stands for Carriage Return Line Feed. So, those people are telling you to use \r\n.To be really technical, a carriage return resets the output caret to the leftmost column, while a line feed brings the said caret down one row. Almost all modern computers (except some bad mail transfer agents) will accept \n, \r, or \r\n as bringing the caret back to the left and down one line. Different OSs use different combinations; Windows \r\n, Linux \n, and the old Macs \r (though apparently they now also use \r\n). So its up to you, but if the standards say use both and you like to stick to standards then use \r\n, it won't mess up your applications.By the way, RFC 1425 talks about the SMTP protocol, and you will find some agents as aforementioned only understand \r\n.Some interesting information from RFC 822

During transmission through heterogeneous networks, it may be necessary to force data to conform to a network's local con- ventions. For example, it may be required that a CR be fol- lowed either by LF, making a CRLF, or by <null>, if the CR is to stand alone). Such transformations are reversed, when the message exits that network.
So basically some networks may only accept CRLF or CR<null>. But RFC 822 was written in 1982 and alot has changed since then...
Link to comment
Share on other sites

From what I've understood, and what the PHP mail reference backs up, is that header fields are always separated by \r\n (CRLF), while lines in the body are separated by \n only. That is what the PHP mail reference indicates:

Each line should be separated with a LF (\n). Lines should not be larger than 70 characters.
Multiple extra headers should be separated with a CRLF (\r\n).
However, RFC 2822 specifically contradicts what the PHP reference says:
2.3. Body The body of a message is simply lines of US-ASCII characters. The only two limitations on the body are as follows: - CR and LF MUST only occur together as CRLF; they MUST NOT appear independently in the body. - Lines of characters in the body MUST be limited to 998 characters, and SHOULD be limited to 78 characters, excluding the CRLF.
It might be possible that PHP is converting \n to \r\n in the body. I've always had success by following what the reference manual says.
Link to comment
Share on other sites

From what I've understood, and what the PHP mail reference backs up, is that header fields are always separated by \r\n (CRLF), while lines in the body are separated by \n only. That is what the PHP mail reference indicates:However, RFC 2822 specifically contradicts what the PHP reference says:It might be possible that PHP is converting \n to \r\n in the body. I've always had success by following what the reference manual says.
Had \n for body, but field was a bit longer than 70. Changed it, but still no email in Lycos (in Yahoo fine). Could there be any other reason for that?Kurt
Link to comment
Share on other sites

Make sure you're setting the from address to match the domain that the email is coming from.
I have done, but no result with Lycos. As it is I use:
				// send the email$body = "Thank you for registering. To activate your account, please click:\n";$body .= "http://www.jalp.co.uk/web/testing/activate.php?x=" . mysql_insert_id() . "&y=$a"; mail($_POST['email'], 'Registration Confirmation', $body, 'From: kurt@jalp.co.uk');

As I said works well for Yahoo and my own domain as such. Is there anyting else in my mail function that might cause problems?Kurt

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...