Pear Mail, how to send plain/text + text/html in UTF-8

China☆狼群 提交于 2019-12-03 02:34:50

I discovered that the headers are supposed to be written differently. In particular, some of them are parameters for the mime object, and not email headers. Then the mime_params array should be passed to the get() function.

This is the correct way to set the headers:

$headers = array(
  'From'          => 'info@mydomain.com',
  'Return-Path'   => 'info@mydomain.com',
  'Subject'       => 'mysubject',
  'Content-Type'  => 'text/html; charset=UTF-8'
);

$mime_params = array(
  'text_encoding' => '7bit',
  'text_charset'  => 'UTF-8',
  'html_charset'  => 'UTF-8',
  'head_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($mime_params);
$headers = $mime->headers($headers);
$mail_object =& Mail::factory('smtp', $GLOBALS['pear_mail_config']);
$mail_object->send('test@mydomain.com', $headers, $body);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!