PHP"邮件()"从功能PHP5 CLI发送邮件但不能当脚本是由浏览器中运行 [英] PHP "mail()" function sends mail from php5 cli but not when the script is run by a browser
问题描述
我是pretty新PHP,和一般的LAMP堆栈,使裸露的我。
I am pretty new to PHP, and the LAMP stack in general, so bare with me.
我已经配置我的服务器通过设置发送邮件sendmail_path =/ usr / sbin目录/ sendmail的
在/etc/php5/apache2/php.ini与sendmail是安装在服务器上。
I have configured my server to send mail by setting "sendmail_path = "/usr/sbin/sendmail"
in "/etc/php5/apache2/php.ini" and sendmail is installed on the server.
当我通过邮件发送就好了CLI运行此脚本,或任何varation,从PHP5,但是当我有一个浏览器中运行它,即Chrome或Firefox,它每次失败。任何想法将AP preciated。
When I run this script, or any varation of it, from php5 via the cli the mail sends just fine, but when I have a browser run it, i.e. Chrome or Firefox, it fails everytime. Any ideas would be appreciated.
<?php
$to = "notreal@email.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
我使用的是PHP5-CLI包命令行间preTER。
I am using the "php5-cli" package for a command line interpreter.
这依赖于PHP其他基于PHP的Web的应用邮件()函数没有任何发送邮件。
Other PHP based web-apps that rely on the PHP "mail()" function don't send mail either.
感谢您的帮助!
推荐答案
的Apache和CLI似乎在你的安装使用不同的配置。
Apache and the CLI seem to use different configurations in your setup.
与Apache的的php.ini
比较 /etc/php5/cli/php.ini
配置。也许自己是不是与Apache的PHP sendmail配置工作,CLI配置是正确的。
Compare the configuration in /etc/php5/cli/php.ini
with your Apache's php.ini
. Probably something is not working with the sendmail configuration for Apache's PHP and the CLI configuration is right.
这篇关于PHP&QUOT;邮件()&QUOT;从功能PHP5 CLI发送邮件但不能当脚本是由浏览器中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!