首先,先安装sendmail通过以下命令
yum install sendmail
安装完后需要做以下设置
setsebool -P httpd_can_sendmail=on
重启服务器或是VPS,修改并变更PHP.INI
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path = /usr/sbin/sendmail -t -i
用以下代码进行测试是否正常工作
<?php
$data = mail("[email protected]", "测试", "测试邮件");
if ($data) {
echo 'success!';
} else {
echo 'fail';
}
转载请注明:无趣的人生也产生有意思的事件 » centos添加邮件代发功能sendmail