站长图库向大家介绍了邮箱服务,php7该如何配置sendmail等相关知识,希望对您有所帮助
假如嫌自己配置服务器麻烦,直接使用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.comset 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地址