PHP发送邮件在命令行但不在PHP文件中工作

时间:2013-12-03 00:08:40

标签: php amazon-ec2 smtp sendmail

我将SMTP设置为电子邮件,并且在使用命令行发送电子邮件时,这非常正常。但是,我编写了这个简单的代码来测试PHP文件,它既不能从浏览器加载,也不能从命令行运行php mail.php。这是简单的代码:

<?php
if(mail("user@gmail.com","Testing PHP","Hope this works!"))
    print "Email successful";
else
    print "Failure";
?>

当我运行php mail.php时,我得到了一个

Authorization Failed (xxxx Too Many Login Attemps, please try again later)

消息......这让我感到困惑,因为它只是在使用命令行函数时才通过授权。

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

这取决于您的发行版。例如。在Debian上有CLI(命令行)和webserver php的分离配置(也取决于你如何运行php脚本cgi,fpm等)。

在配置/etc/php5/cli/php.ini中,您可能对mail function部分:

感兴趣
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path = sendmail -t -i

确保您已正确配置SMTP,您可以从控制台进行测试:

php -r 'mail("test@example.com","Testing php -v ".phpversion(),"php on ".gethostname());'
相关问题