关于pear mail的发送中文邮件乱码可以参考

来源:互联网 发布:java负数转正数 编辑:程序博客网 时间:2024/05/17 23:00
最近工作需要,发现网上很多


关于pear mail,发送中文邮件的出现乱码,资料都是不全面。最后只有自己去官网下载最新版本整合,经测试,国内的邮箱估计没大问题,国外的看运气~~~微笑


资源下载地址:http://download.csdn.net/detail/chenfei829/9302599


测试页的代码如下(两个):


<?//=========================================================================//此法应该杜绝大部分的中文乱码现象,但也打不了保票的//=========================================================================header('Content-type: text/html;charset=GBK');require_once 'mail2/Mail.php'; require_once 'mail2/mime.php';$conf['mail'] = array( 'host'     => 'smtp.xxxx.com',//smtp服务器地址 'port'   => 25,'auth'     => true,//true表示smtp服务器需要验证,false不需要 'username' => 'intranet@xxxx.com',//用户名 'password' => 'xxxxx'//密码 );$hdrs = array(            'From'=>'central@xxxx.com',//显示发信地址            'Subject'=>"=?gb2312?B?".base64_encode('系统测试下订单:PO99999999')."?=" //标题,处理中文乱码    );//内容编码设置$crlf = array('head_charset' => 'gb2312','text_charset' => 'gb2312','html_charset' => 'gb2312',);//邮件正文 两种格式测试 $mailbody = "您好!\n\n      系统提醒您:\n\n      系统发送了订单:".$lv_po_number."\n\n      请及时登录“系统”处理:http://www.xxxxx.com/cp/\n\n      系统邮件请勿回复!如有疑问请致电:209 ";$mailbody2 = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\" /></head><body>您好!<br><br>     系统提醒您:<br><br>     系统发送了订单:PO99999999<br><br>     请及时登录“系统”处理:http://www.xxxxx.com/cp/<br><br>     系统邮件请勿回复!如有疑问请致电:209 </body></html>";$mime = new Mail_mime($crlf);    $mime->setTXTBody($mailbody);//$mime->setHTMLBody($mailbody2);    $body = $mime->get();    $hdrs = $mime->headers($hdrs);         $mail =  & Mail::factory('smtp',$conf['mail']);    $succ = $mail->send('xxxx@163.com,xxxx@qq.com',$hdrs,$body);//多人用“,”分隔echo "发送结束_mime";exit;?>



<?//=========================================================================//该方法发送的邮件,会遇到乱码的情况//国外邮箱才会出现中文乱码//=========================================================================header('Content-type: text/html;charset=GBK');require_once 'mail2/Mail.php'; $conf['mail'] = array( 'host'     => 'smtp.xxxx.com',//smtp服务器地址 'port'   => 25,'auth'     => true,//true表示smtp服务器需要验证,false不需要 'username' => 'intranet@xxxx.com',//用户名 'password' => 'xxxxx'//密码 );//发送下单邮件$headers['From']    = 'central@xxxx.com';//显示发信地址 $headers['To']      = 'xxxx@163.com'; //收信地址 -- 多人用“,”分隔$headers['Subject'] = "=?gb2312?B?".base64_encode("测试下订单:PO12345678")."?="; //邮件标题 中文乱码处理$mail_object = &Mail::factory('smtp', $conf['mail']);    //邮件正文 $body = "您好!\n\n      系统提醒您:\n\n      系统发送了订单:PO12345678\n\n      请及时登录“系统”处理:http://www.xxxxx.com/cp/\n\n      系统邮件请勿回复!如有疑问请致电:209 ";$mail_res = $mail_object->send($headers['To'], $headers, $body); //发送供应商echo "发送结束_Mail";exit;?>


0 0
原创粉丝点击