Reputation: 11
How do I correctly set the text encoding for a multi-part email using Pear
?
I've looked at many examples and I believe I am setting it correctly. However, When sending emails they are arriving with charset=ISO-8859-1
even though I specify UTF-8
.
This problem began when I decided to send a multi-part email with both text and HTML parts. I have tried setting a content type but it does not appear to make a difference.
Below is the code I am using. Any suggestions appreciated.
function send_html_email($to, $from, $subject, $html, $plainTxt ) {
require_once "Mail.php";
require_once "Mail/mime.php";
$host = "ssl://secure.xxx.com";
$port = "xxx";
$username = "xxx";
$password = "xxx";
$headers = array (
'charset' => 'UTF-8',
'From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version' => "1.0"
);
$crlf = "\n";
$mime = new Mail_mime($crlf);
$mime->setHTMLBody($html);
$mime->setTXTBody($plainTxt);
$body = $mime->get();
$headers = $mime->headers($headers);
$smtp = Mail::factory('smtp', array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
}
Upvotes: 1
Views: 1539
Reputation: 24579
Try headers like such:
$headers['Content-Type'] = "text/plain; charset=\"UTF-8\"";
$headers['Content-Transfer-Encoding'] = "8bit";
Reference: http://pear.php.net/manual/en/package.mail.mail.factory.php#13207
As a side note, Pear is "a framework and distribution system for reusable PHP components". The Mail component is just one of the many available through Pear.
Upvotes: 1