[SOLVED] Outlook stripping newline character - Sendgrid

We've recently modified our ecommerce web application, and replaced the native PHP mail functionality with a phpmailer and SMTP. It was a pretty straight forward 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 were 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 was automatically converting plain/text email to HTML format. We disabled this by logging into the Sendgrid account, and going to Account -> Global Settings and unchecking "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 the 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 customer 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".