.
3ss.cn

为了使用邮箱服务,php7该怎么配置sendmail

Sendmail作为一种免费的邮件服务器软件,已被广泛的应用于各种服务器中,它在稳定性、可移植性、及确保没有bug等方面具有一定的特色,且可以在网络中搜索到大量的使用资料。

假如嫌自己配置服务器麻烦,直接使用PHPMailer调用第三方邮件服务器,简单省事。git地址如下:

https://github.com/PHPMailer/PHPMailer

1.安装组件

yum install sendmail mailx

2.修改配置文件/etc/mail.rc

添加下列参数:

set from=acc@163.com  #发送方
set smtp=smtp.163.com
set smtp-auth-user=acc@163.com #账号
set smtp-auth-password=password #授权码
set smtp-auth=login

3.命令行发送邮件测试

echo "测试邮件" | mail -s '请在明天下午联系我' 111@qq.com

此时在PHP脚本中调用mail函数,会返回false,打开错误日志,显示:

May 23 13:09:26 localhost sendmail[3901]: NOQUEUE: SYSERR(php-fpm): /etc/mail/sendmail.cf: line 0: cannot open: Permission denied

因为我们还没开启对于httpd发送邮件的支持

4.开启httpd发送邮件支持

setsebool -P httpd_can_sendmail 1

5.假如出现dsn:service unavailable错误,需要修改hostname

hostname <hostname> #假如是本地服务器,尝试设置为本地IP地址
赞(0)
未经允许不得转载:互联学术 » 为了使用邮箱服务,php7该怎么配置sendmail

评论 抢沙发