以ubuntu为例
php
修改php.ini,若是是php-fpm,须要修改2个php.ini文件shell
sendmail_from = "123@123.com" //发送邮件的邮箱,必定要和from对应 sendmail_path = "sendmail -t -i -f 123@123.com"
安装或者从新配置postfix
ubuntu
sudo apt-get install postfix //若是已经安装,从新配置 //sudo dpkg-reconfigure postfix
一路用默认吧,第一个能够用发邮件用的域名,后面尽可能为空,或者用默认值,我在这个地方卡住很久vim
添加发邮件用的服务器地址以及发邮件的帐户密码服务器
sudo vim /etc/postfix/sasl_passwd [smtp.123.com] 123@123.com:密码
保存后
php-fpm
sudo postmap /etc/postfix/sasl_passwd sudo postfix reload
编辑/etc/postfix/main.cf,添加post
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发送者是否正确code