Pear's mail_mine not working with Outlook

In a WordPress plugin I am developing, I am using Pear’s mail_mime to generate an HTML email and send it with an attachment. This worked fine for me during testing with my gmail account. However once I started using the plugin to send emails to others, Outlook users were getting a garbled mess. Outlook could not properly understand the generated multipart/mixed message and was showing the raw text. It took a bit of digging to discover the solution, but the root of the issue goes back to an age-old C.S. problem.

Windows uses ‘rn’ to define a line break, while Unix-like systems use ‘n’ to define a line break. Gmail doesn’t care which kind of line break you use, but Outlook requires line breaks to be in the ‘rn’ format.

Mail_mime allows you to pass the default for line breaks as a constructor argument. However, this didn’t work correctly for me. The Mail_mime code uses the End-Of-Line constant (PHP_EOL) and passing the EOL value in was not enough to change the value in all places.

What I had to do to finally get Outlook emails to display correctly was to first define the PHP_EOL constant and then pass it in as well.

// define the PHP_EOL constant
if (!defined('PHP_EOL')) define ('PHP_EOL',"rn");
// pass in the value on create
$mime = new Mail_mime(PHP_EOL);

I had to define the constant AND pass in the value to catch all the places the linebreak characters were used. This seems like a bug in Mail_mime.

I used the comments on this bug report to solve this issue. Unfortunately since this work-around was discovered, the maintainers don’t seem willing to fix this issue.

Advertisement

WordPress Errors With 1and1 Hosting

Occasionally WordPress experiences problems when uploading images or upgrading plugins. After some Googling I found the solution on this site.

You need to add these lines to your .htaccess file. If you don’t have the file just create one.

Options All -Indexes
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php

This will make sure that all php files are treated as php 5.

WordPress Source Code Syntax Highlighting for Coldfusion

If I’m going to blog about code, I need a good syntax highlighter for WordPress. Searching through the many plug-ins available its obvious that there are really only two choices: Plugins that use Google’s Prettify and Plug-ins that use GeSHi.

I first tried the “Google Syntax Highlighter for WordPress” plug-in only to find that it doesn’t do Coldfusion. I downloaded someone’s plug-in for Google’s plug-in that would do Coldfusion Syntax highlighting only to have it start breaking the page layout. There was also a noticable slow down in the page loading. I gave up after spending my morning trying to get this to work.

The next plug-in I tried was “WP-Syntax” which is based on GeSHi. Not only did it support Coldfusion right out of the box, but it worked perfectly the first time I used it! If anyone else needs Coldfusion Source Code Syntax Highlighting for WordPress I highly recommend checking out the “Wp-Syntax” plug-in.

Example:
(Code box begins with <pre lang=”cfm”>)


The other plug-in you’ll probably need is the “Raw-HTML” plug-in. This will help keep WordPress from being helpful and scrambling up your code. Unfortunately this doesn’t solve the issue of switching between the HTML tab to the Visual tab. If you do that WordPress will still eat your code.