HTML Email with Text Plain Backup. Notes for MIME::Lite and PHP Pear

Recently I’ve been working on some code that needed to have HTML email sent along with plain text email.  One application was the “email a photo” option for Resizr.com.  The other option, and the one where it wasn’t working right, was for PostOnce.net, basically a trucking logistics company.  The trucking industry isn’t the most high tech, and there are still people out there using email clients that don’t support HTML.

Anyway, here we go.

With PHP Pear, the code is smart enough to figure things out itself.  However, with MIME::Lite, you have to build the message yourself.

The answer to the problem is to use the “Multipart/Alternative” as your mime type, put the text/plain part first (for AOL support), and don’t attach the HTML as a file (attach it as data).

Example:

my $mime_msg = MIME::Lite->new(
    From => “matt@urbanpug.com”,
    To   => $email,
    Subject => ‘multipart/alternative’,
    Type => $mime_type,
) or die “Error creating MIME body: $!\n”;

$mime_msg->attach(Type => ‘text/plain’,
    Data => qq{ Your Message Body });

$mime_msg->attach(Type => ‘text/html’,
    Data => qq{ Your HTML Message Body });

However, I had a problem.  I was calling various scripts to build a big HTML file, which would then be attached, so i was doing:

$mime_msg->attach(Type => ‘text/html’,
    File => $html_file_path);

Don’t do that.  Instead, read the file into an array, then join the array into a string.  I dont know why, but some mail readers (including gmail) saw that the HTML attached was a file, and treated it as an attachment, rather than an alternative way of presenting the same message.

Hope this helps you!  If you have anything to add, reply!

All powerful email client of the future incorporating current memes

Ok, big enough title? Simple idea.

I think it would be interesting for there to be an emai -> todo list convergence app, with the following features.

  1. Let all email be tagged both automatically (text scan) and by hand
  2. Allow easy manual tagging (possibly w/ tree-based tag finding)
  3. Allow filters that will automatically tag mail based on features of the mail (from an individual, from a mailing list, with a subject line, etc.
  4. Allow ‘views’ of mail to be created that shows mail based on how the mail is tagged
  5. Allow todo items to be created easily from mail
  6. Allow tags to be associated w/ todo lists and todo list items