I'm trying to send an email in both text and html, but I can't correctly send the right headers. In particular, I'd like to set the Content-Type header, but I can't find how to set it separately for html and text parts.
This is my code:
$headers = array(
'From' => 'info@mydomain.com',
'Return-Path' => 'info@mydomain.com',
'Subject' => 'mysubject',
'text_encoding' => '7bit',
'text_charset' => 'UTF-8',
'html_charset' => 'UTF-8',
'head_charset' => 'UTF-8',
'Content-Type' => 'text/html; charset=UTF-8'
);
$mime = new Mail_mime();
$html = '<html><body><b>my body</b></body></html>';
$text = 'my body';
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$body = $mime->get();
$headers = $mime->headers($headers);
$mail_object =& Mail::factory('smtp', $GLOBALS['pear_mail_config']);
$mail_object->send('test@mydomain.com', $headers, $body);
That's the email I get:
From: info@mydomain.com
Subject: mysubject
text_encoding: 7bit
text_charset: UTF-8
html_charset: UTF-8
head_charset: UTF-8
Content-Type: multipart/alternative;
boundary="=_7adf2d854b1ad792c802a9db31084520"
Message-Id: <.....cut.....>
Date: Mon, 8 Oct 2012 15:40:54 +0200 (CEST)
To: undisclosed-recipients:;
--=_7adf2d854b1ad792c802a9db31084520
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="ISO-8859-1"
my body
--=_7adf2d854b1ad792c802a9db31084520
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset="ISO-8859-1"
<html><body><b>my body</b></body></html>
--=_7adf2d854b1ad792c802a9db31084520--
It seems that the Content-Type header I set is totally ignored. I'd have expected some setHTMLHeaders and setTXTHeaders functions, but it seems like there's nothing like this. Am I missing something? How can I set both Content-Type headers to UTF-8?