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="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");
直接在php.ini中修改,
- sendmail_path = /usr/sbin/sendmail -f admin@aizher.com -t -i