解决升级php版本后mail发送邮件失败问题

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 = "[email protected]";
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

至此,问题解决

猜你喜欢

转载自blog.csdn.net/dreamstone_xiaoqw/article/details/80973296