civilvar 发表于 2015-11-25 13:45:28

Linux配置sendmail实现PHP发送邮件


Linux配置sendmail实现PHP发送邮件


1.安装sendmail

yum -y install sendmail

2.安装mail命令



yum -y install mailx

3.开启sendmail



/etc/rc.d/init.d/sendmail start

4.设置开机启动



vim /etc/rc.local

最后一行添加上:



/etc/rc.d/init.d/sendmail start

5.这时写1个简单mail函数已经可以发送邮件:



mail(“接受方email“,”邮件主题”,”正文内容”,”from:发送方email”);

但是还存在以下问题:

1.邮件标题、内容中文乱码

2.邮件内容不支持html



6.优化



$from = '发送方email';
$to = '接受方email';
$title = '时间你好123!@#¥%……&*()subject';
$subject = "=?UTF-8?B?".base64_encode($title)."?="; //解决标题中文乱码
$body = '<a href=&quot;http://www.baidu.com&quot; target=&quot;_blank&quot;>link</a>';
// 实现邮件内容支持html
$headers[] = &quot;From: $from&quot;;
$headers[] = &quot;X-Mailer: PHP&quot;;
$headers[] = &quot;MIME-Version: 1.0&quot;;
$headers[] = &quot;Content-type: text/html; charset=utf8&quot;;
$headers[] = &quot;Reply-To: $from&quot;;
mail($to, $subject, $body, implode(&quot;\r\n&quot;, $headers), &quot;-f $from&quot;);







直接在php.ini中修改,



view
plaincopy


[*]
sendmail_path = /usr/sbin/sendmail -f admin@aizher.com -t -i









页: [1]
查看完整版本: Linux配置sendmail实现PHP发送邮件