Alexey Zakhlestin's Blog

Programming for Mac and Web

SMTP Legacy

Permalink

Some things still wonder me, after 10+ years of web-development. Todays wonder is here:

RFC2821 (SMTP) tells: The maximum total length of a text line including the is 1000 characters. In real world, most MTAs default to 990 characters per-line, which means, that if you will try to dump longer line on them, they would split it by putting ”!\n” after 990-th byte. This is mostly harmless for plain-text, but can easily break html.

Actually, there is even a PHP-bug reported, regarding this, but PHP obviously can’t do anything to help the situation

The solution is really simple: if there is a chance, that lines of your emails would be longer than 990 bytes encode body using base-64. The easiest way to do it for emails without attachments, in php is to use mb_send_mail() function instead of mail(), as it will apply encoding automatically.

Comments