[SOLVED] Outlook stripping newline character - Sendgrid

We've recently modified our e-commerce web application and replaced the native PHP mail functionality with a Phpmailer and SMTP. It was a pretty straightforward change, and we kept the mail format to "Plain/Text" format and changed the mail host to "smtp.sendgrid.net". After the change, we've noticed that the newline "\n" wasn't interpreted correctly and the mail we received was all garbled up. After some investigation, we found 2 things that needed to be changed to correct the problem.

1. If Click Tracking is enabled on Sendgrid, the Sendgrid automatically converts plain/text email to HTML format. We disabled this by logging into the Sendgrid account and going to Account -> Global Settings and unchecking the "Don't convert plain text email to HTML" check box as shown on the following Sendgrid knowledgebase.

2. Now, the email we received on webmail displayed correctly, but Outlook still stripped off newline characters. After some more investigation, we've found that Outlook strips out what it identifies as an unnecessary carriage return. If you open the email in Outlook you'll see a little informational bar at the top of the email explaining that Outlook has removed extra line breaks and that you can click it to add them back in (see screenshot below). Furthermore, you can configure Outlook to never remove such carriage returns by going to Tools -> Options, clicking the E-mail Options button, and then unchecking “Remove extra line breaks in plain text messages.

It's not a good idea to ask your customer to fix the problem that was introduced from your end. Technically, the problem is Outlook but your customers don't really care if it's Outlook that is misbehaving. The solution is to send CRLF instead of LF only - we still live in the DOS/Windows world. In the PHP code, we'll add "\r\n" to the body of the message instead of just "\n".

Share this post

Comments (0)

    No comment

Leave a comment

All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.


Login To Post Comment