doutan2228 2011-12-22 18:27
浏览 124
已采纳

PHP“mail()”函数从php5 cli发送邮件,但不是在浏览器运行脚本时发送邮件

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.

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,

How are you?";
 if (mail($to, $subject, $body)) {
   echo("<p>Message successfully sent!</p>");
  } else {
   echo("<p>Message delivery failed...</p>");
  }
?>

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

Other PHP based web-apps that rely on the PHP "mail()" function don't send mail either.

  • 写回答

3条回答 默认 最新

  • dongyong5912 2011-12-22 18:43
    关注

    Apache and the CLI seem to use different configurations in your setup.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制