Archived Forum Post

Index of archived forum posts


Base64 encoded mail with SMTP/PHP

Aug 17 '12 at 02:02


I have problem with e-mail encoding. I try to send a base64 encoded mail with this code:

$mailman = new CkMailMan();

$email = new CkEmail();
$email->AddHeaderField("Content-Transfer-Encoding", "base64");
$email->AddHeaderField("MIME-Version", "1.0");
$email->AddHeaderField("Content-Type", "text/html; charset=utf-8");
$email->AddHeaderField("X-Priority", "1");
$email->AddHeaderField("X-MSMail-Priority", "High");
$email->AddHeaderField("Importance", "High");
$email->AddHeaderField("From", "=?UTF-8?B?".base64_encode("From Name")."?=\n"." <from_mail@aaa.bbb>");          
$email->SetHtmlBody("An HTML body.");
$email->put_From("From Name <from_mail@aaa.bbb>");
$email->AddTo("To Name", "");

The sending is successfull but the content is not encoded. What's wrong with my code?

Regards, Adam



The Content-Transfer-Encoding header field applies to the MIME body, but not the headers. The Chilkat Mail API is designed to automatically handle things such as encoding/decoding, charset conversion, etc. For example, if Asian language chars are included in the Subject, or From/To names, then those header fields will automatically be "B" encoded, using the charset of the email, whatever that may be. On the other hand, if 8bit latin chars are present, then the header fields containing those chars might be "Q" encoded. Chilkat will automatically choose the most appropriate encoding. If the chars are 7bit us-ascii, then there is no need for "Q" or "B" encoding.

I'm sorry to say that it's not possible to explicitly do what you are requesting. You may find it odd, but on the other hand, if Chilkat didn't do so many things automatically, then the learning curve for sending and/or reading email would be orders of magnitudes higher.


Thank you for your reply!