How to fix: random exclamation marks in e-mails

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.

Line length limits were defined in the Internet standard RFC 2822 and subsequently in RFC 5322. (Warning: they are long and dry reading, although if you’re already reading this post…)

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" );

Speak your mind

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word