|
Linux配置sendmail实现PHP发送邮件
[size=1em]
1.安装sendmail
yum -y install sendmail
[size=1em]
2.安装mail命令
yum -y install mailx
[size=1em]
3.开启sendmail
/etc/rc.d/init.d/sendmail start
[size=1em]
4.设置开机启动
vim /etc/rc.local
[size=1em]
最后一行添加上:
/etc/rc.d/init.d/sendmail start
[size=1em]
5.这时写1个简单mail函数已经可以发送邮件:
mail(“接受方email“,”邮件主题”,”正文内容”,”from:发送方email”);
[size=1em]
但是还存在以下问题:
[size=1em]
1.邮件标题、内容中文乱码
[size=1em]
2.邮件内容不支持html
[size=1em]
[size=1em]
6.优化
$from = '发送方email';
$to = '接受方email';
$title = '时间你好123!@#¥%……&*()subject';
$subject = "=?UTF-8?B?".base64_encode($title)."?="; //解决标题中文乱码
$body = '<a href="http://www.baidu.com" target="_blank">link</a>';
// 实现邮件内容支持html
$headers[] = "From: $from";
$headers[] = "X-Mailer: PHP";
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=utf8";
$headers[] = "Reply-To: $from";
mail($to, $subject, $body, implode("\r\n", $headers), "-f $from");
[size=1em]
[size=1em]
直接在php.ini中修改,
[html] view
plaincopy
sendmail_path = /usr/sbin/sendmail -f admin@aizher.com -t -i
[size=1em]
[size=1em]
|
|
|