postfix php mail,利用postfix让PHP的mail函数生效

以ubuntu为例

修改php.ini,如果是php-fpm,需要修改2个php.ini文件

sendmail_from = "123@123.com" //发送邮件的邮箱,一定要和from对应

sendmail_path = "sendmail -t -i -f 123@123.com"

安装或者重新配置postfix

sudo apt-get install postfix

//如果已经安装,重新配置

//sudo dpkg-reconfigure postfix

一路用默认吧,第一个可以用发邮件用的域名,后面尽量为空,或者用默认值,我在这个地方卡住好久

添加发邮件用的服务器地址以及发邮件的账户密码

sudo vim /etc/postfix/sasl_passwd

[smtp.123.com]     123@123.com:密码

保存后

sudo postmap /etc/postfix/sasl_passwd

sudo postfix reload

编辑/etc/postfix/main.cf,添加

relayhost = [smtp.123.com] //这个地方要和前面一样

# enable SASL authentication

smtpd_sasl_auth_enable = yes

smtp_sasl_auth_enable = yes

# disallow methods that allow anonymous authentication.

smtp_sasl_security_options = noanonymous

# where to find sasl_passwd

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

新建php文件进行测试

mail('123@123.com', 'My Subject', 'fuck'); //发给自己

看是否收到邮件,如果遇到问题,看/var/log/mail.log文件,重点是to收件人是否正确,relay是否是[smtp.123.com],from发送者是否正确

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值