First published on August 20, 2013
If you are programmatically sending e-mails, you might troubleshoot random question marks and random exclamation marks in e-mail bodies. Question marks are often caused by a character encoding issue. Exclamation marks are often caused by a line length issue, and that is almost certainly the case if the seemingly random exclamation mark is followed by a line break. If you view the source of an e-mail — in the Thunderbird e-mail client you can do this by clicking “View > Message Source” — it will be much easier to spot whether you have really long lines of characters.
Specifically, those standards state:
“Each line of characters MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.”
(The CRLF refers the line break.)
In PHP, you can use the wordwrap function to auto-wrap long lines.
// Force the lines to wrap at 75 characters; if more than 998 characters, you will end up with a forced line break and an exclamation mark // Note: this is not UTF-8 safe but that's OK because we're not allowing it to cut in the middle of a word $emailBody = wordwrap( $emailBody, 75, "\r\n" );