Click to See Complete Forum and Search --> : Sending a HTML email in base64 - HELP


cdp103188
07-01-2008, 11:20 AM
I have been sending HTML emails via HTML forms on my website for a while now using the following method.

$base64contents = rtrim(chunk_split(base64_encode($message)));

But, all of a sudden it quit working. Now instead of seeing my nice HTML tables and stuff, I just see a bunch of base64 nonsense.

I am using Mozilla Thunderbird to receive emails, and I set it to where I can see all of the headers for the email, and on the old emails it shows this as a header:

Content-Transfer-Encoding: base64

but on the new emails (that don't load correctly) that header is missing, and instead it appears in the body of the email just before the un-decoded base64 contents.

Here is the code I use to send the email:

$base64contents = rtrim(chunk_split(base64_encode($message)));

$to = "kit@huntingsportsplus.net";
$subject = "$lastName, $firstName - $propertyCounties, $propertyStates - $totalAcreage Acres - $emailAddress";
$headers .= "From: info@hunt-private-land.com" . "\r\n";
$headers .= "Cc: " . "\r\n";
$headers .= "Bcc: cameron@huntingsportsplus.com" . "\r\n";
$headers .= "Content-Type: text/html" . "\r\n";
$headers .= "Content-Transfer-Encoding: base64" . "\r\n";

mail($to,$subject,$base64contents,$headers);

One thing that has changed right before the emails stopped loading correctly is this; we just switched from a shared hosting plan to a virtual dedicated server. Is it possible that our new vd server does not support base64 encoded emails?

Please help me out here.

BTW - when I copy the "nonsense" in the emails and paste it into an online base64 encoder/decoder it comes out as html, and when I plug this html into my html editor, the html loads just as it should in the preview pane - everything seems to be fine within the html once it has been decoded from the base64 garble.

hastx
07-01-2008, 08:20 PM
There are three principles you have to remember when compiling emails

The encoding type exists for the sake of routers (and being able to relay content reliably)
Not all mail servers and or client apps support html inline messages, so they should be in multipart.
Some servers and client apps imply certain things, others need all the info, including the intended mime version and charset.


To tell if the router is the problem try "quoted/printable" encoding type ...or maybe even 7bit ...it's not optimum but it should give you different results.

to test the server and client apps, make sure to specify the mime version and charset intended, its not always implied...also, since you are not doing the message in multipart and trying to display the message in line, I wouldn't even chunck-split it. Try:


.......
$to = "kit@huntingsportsplus.net";
$subject = "$lastName, $firstName - $propertyCounties, $propertyStates - $totalAcreage Acres - $emailAddress";
mail ($to,$subject,$message,"From: info@hunt-private-land.com <info@hunt-private-land.com>\n"."MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1");

cdp103188
07-02-2008, 09:09 AM
Worked like a dream. Thank you very much for your prompt and accurate reply. :D