Here is the second post in my wednesday posting fest of terror….ok i’ll calm down. This one is concerned with using Joomla mailer, which in turn is based upon the PhpMailer class.

I came across a bug when working on an ecommerce site. The site had to send invoice email to users, but the html in the email was bei! ng bro !ke up by exlca!mation ma !rks. See how annoying that is! To fix this I had to base64 encode the body of the email. But you need to indicate to the mail client that you have done so, or you will get gibbereish. So you need to set a custom header. The following code sums up the process

$body = rtrim(chunk_split(base64_encode("crazy amount of content here...."));
$mailer->AddCustomHeader("Content-Transfer-Encoding: base64");
$mailer->setBody($body);

This solved the problem, thankfully :p