DATA: 2018年07月09日 16:27:21
CentOS7系统php版本从5.3升级至5.6后,原本的邮件发送功能失效。查阅资料解决并笔记之。
php发送邮件主要代码实现
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: <'.$msg->email.'>' . "\r\n";
$myEmail = "dream@yixzm.cn";
mail($myEmail, $msg->subject, $msg->edit, $headers);
打开etc下的php配置文件:/etc/php.ini,取消sendmail_path的注释
; 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
测试sendmail,报错:
sendmail: fatal: parameter inet_interfaces: no local interface found for ::1
参考博文: send-mail: fatal: parameter inet_interfaces: no local interface found for ::1
将main.cf中的init_interface配置localhost改为all
vi /etc/postfix/main.cf
inet_interfaces = all
至此,问题解决