【发布时间】:2014-01-13 18:20:34
【问题描述】:
我有一个通过 cron 运行的文件。向用户发送电子邮件的文件。
但是有一个问题,问题是当我通过浏览器打开文件时,用于读取邮件的 PHP 参数正确设置了正确的发件人,我在 From:
当文件被 cron 执行时,sender 被忽略,以 Linux 用户名和主机名作为 sender。
$headers = "";
$headers .= "MIME-Version: 1.0" . "\n";
$headers .= "Content-type: text/html; charset=utf-8" . "\n";
$headers .= "Content-Transfer-Encoding: 8bit". "\n";
$headers .= "Date: ".date("r"). "\n";
$headers .= "To: ". $users. "\n";
$headers .= "From: Somthing <no-reply@mydomain.com>" . "\n";
mail($to, "Remainder 1", "Message body", $headers);
Cron 设置是这样的
/usr/local/bin/php -q /home/user/cron.php
【问题讨论】:
-
可能是因为 cron 是通过
root运行的。 -
用户可以运行cron吗?
-
是的,先
crontab -u user然后-l(列表)或-e(编辑) -
是
Somthing从您的配置中复制和粘贴,还是您为 SO 更改了这个?