PHP“邮件()"函数从 php5 cli 发送邮件,但在浏览器运行脚本时不发送 [英] PHP "mail()" function sends mail from php5 cli but not when the script is run by a browser

查看:22
本文介绍了PHP“邮件()"函数从 php5 cli 发送邮件,但在浏览器运行脚本时不发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过在/etc/php5/apache2/php.ini"中设置 "sendmail_path = "/usr/sbin/sendmail" 来配置我的服务器来发送邮件,并且 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 从 php5 运行此脚本或它的任何变体时,邮件发送得很好,但是当我使用浏览器(即 Chrome 或 Firefox)运行它时,它每次都失败.

When I run this script, or any variation 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.

<?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"包用于命令行解释器.

I am using the "php5-cli" package for a command line interpreter.

其他依赖 PHPmail()"函数的基于 PHP 的网络应用也不发送邮件.

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.

/etc/php5/cli/php.ini 中的配置与您的Apache 的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“邮件()"函数从 php5 cli 发送邮件,但在浏览器运行脚本时不发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆