SMTP legacy

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

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • DZone
  • FriendFeed
  • Reddit
  • Tumblr
  • Twitter
Liked this post? Follow me on twitter:@jimi_dini.

  • http://magnetikonline.com/ Peter Mescalchin

    Another solution is to encode your mail bodies using quoted-printable,either with a pure PHP solution or using the imap_8bit() function from the IMAP lib.

    Agreed,it does show how arcane the whole internet mail thing really is :)

A sample text widget

Etiam pulvinar consectetur dolor sed malesuada. Ut convallis euismod dolor nec pretium. Nunc ut tristique massa.

Nam sodales mi vitae dolor ullamcorper et vulputate enim accumsan. Morbi orci magna,tincidunt vitae molestie nec,molestie at mi. Nulla nulla lorem,suscipit in posuere in,interdum non magna.