<?php
require_once('Mail.php');
require_once('Mail/mime.php');
$to = 'xxx@gmail.com'; //收信人
$headers['From'] = 'xxx@126.com'; //发信人
$subject = '测试中文';//标题
$headers['Subject'] = "=?UTF-8?B?".base64_encode($subject)."?="; //标题乱码
$mime = new Mail_mime;
$html ='<html><body>测试中文邮件</body></html>';
$mime->setHTMLBody($html);
//发送附件
$file = 'E:xampphtdocspsmakcmsb75cb65985fea646a3d7e6586e2d9e22.jpg'; //附件地址,该文件夹需要读权限
$mime->addAttachment($file,'image/jpg');
$param["html_charset"] ='utf-8'; //内容乱码
$body = $mime->get($param);
$headers = $mime->headers($headers);
$params['host'] = 'smtp.126.com'; //你需要先弄清你要借助哪个服务器来发邮件,去找找流行邮箱的帮助文档,这里写的是126邮箱
$params['auth'] = true;
$params['username'] = 'xxx@126.com' ;
$params['password'] = 'xxx';
$message = & Mail::factory('smtp',$params);
$message->send($to,$headers,$body);
?>