解决docker内不能用php发邮件问题
用php mail发送邮件 ,docker 提示 cant connect to remote host (127.0.0.1): Connection refused。
问题来源于sendmail
解决办法 安装ssmtp
进入docker
apt-get install -q -y ssmtp mailutils /
echo "mailhub=smtp.gmail.com:587" >> /etc/ssmtp/ssmtp.conf /
echo "AuthUser=youMail@gmail.com" >> /etc/ssmtp/ssmtp.conf /
echo "AuthPass=youPassword" >> /etc/ssmtp/ssmtp.conf /
echo "UseTLS=YES" >> /etc/ssmtp/ssmtp.conf /
echo "UseSTARTTLS=YES" >> /etc/ssmtp/ssmtp.conf /
# 显示 发件人
echo "FromLineOverride=YES" >> /etc/ssmtp/ssmtp.conf
#如果已经在php.ini里面设置了这步可以省却
echo "sendmail_path=sendmail -i -t" >> /usr/local/etc/php/conf.d/php-sendmail.ini
测试发送
下面2个方法都可以
echo "Subject: Testing Email" | /usr/lib/sendmail -s youMail@gmail.com
echo "Subject: Testing Email" | /usr/sbin/sendmail -s youMail@gmail.com