如何使用ssmtp在php中发送邮件?

时间:2019-11-27 09:09:37

标签: php ubuntu ssmtp

我正在使用Ubuntu 19.10。 我刚刚安装了ssmtp,并按照https://www.nixtutor.com/linux/send-mail-with-gmail-and-ssmtp/中的说明重新配置了文件/etc/ssmtp/ssmtp.conf

所以我的 /etc/ssmtp/ssmtp.conf 看起来像-

# Make this empty to disable rewriting.
root=demo@gmail.com

# The place where the mail goes. The actual machine name is required no 
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
#rewriteDomain=

# The full hostname
hostname=127.0.1.1:80
UseSTARTTLS=YES
AuthUser=demo@gmail.com
AuthPass=123456

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

php.ini
中的邮件路径 sendmail_path /usr/sbin/sendmail -t -i

和用于发送邮件的自定义php脚本 send_mail.php -

<?php
  // the message
  $msg = 'Testing for send mail in Linux';
  // send email
  $send = mail('demo@gmail.com','My subject',$msg);
  echo $send ?  'MAIL SENT' : 'MAIL NOT SENT';
?>
通过浏览器运行时

输出
邮件未发送
通过终端( php send_mail.php )运行时输出
sendmail:(127.0.1.1:80)
邮件未发送

请帮助我!

0 个答案:

没有答案