cron作业为php执行不同

我使用opendkim(centos)在我的服务器上设置了dkim。 当PHP执行邮件命令(在网站上,例如forget.php)。 它发送一封与DKIM签名的电子邮件。 但我也设置了一个cron作业来运行mailcron.php发送电子邮件。

我通过键入crontab -e设置cron [ENTER] * / 5 * * * * php -q /var/www/html/mailcron.php [保存]

从cron日志输出

Jul 21 03:15:01 veepiz crond[3819]: (root) CMD (/etc/webmin/status/monitor.pl) Jul 21 03:15:01 veepiz crond[3820]: (root) CMD (/etc/webmin/virtual-server/collectinfo.pl) Jul 21 03:15:01 veepiz crond[3821]: (root) CMD (php -q /var/www/html/mailcron.php) 

为什么使用cron发送的电子邮件没有签名,而那些直接从网站签名运行的邮件。

 <?php set_time_limit(0); error_reporting(E_ALL); $dbserver='localhost'; $dbuser='cccc'; $dbpassword='xxxx'; $dbname='veepiz'; $homepath="http://www.veepiz.com"; $supportemail="[email protected]"; $localpath = ''; $domainpath = '.veepiz.com'; $dblink=mysql_connect($dbserver,$dbuser,$dbpassword); require("class.phpmailer.php"); if (!$dblink) { die('Could not connect to database.<br/>'.mysql_error()); } if (!(mysql_select_db($dbname,$dblink))) { die('Could not select database<br/>'.mysql_error()); } $q="SELECT * FROM emailcron ORDER BY id ASC"; $r=mysql_query($q); if ($r) { if (mysql_num_rows($r)>0) { $message=""; $n=0; $c=0; while ($o=mysql_fetch_object($r)) { $x = new PHPMailer(); $x->From = "[email protected]"; $x->FromName = "Veepiz"; $x->AddAddress($o->emailaddress,$o->toname); $x->AddReplyTo("[email protected]", "Veepiz"); $x->WordWrap = 50; // set word wrap to 50 characters $x->IsHTML(true); // set email format to HTML $x->Subject = $o->subject; $x->Body = nl2br($o->content); $x->AltBody = strip_tags($o->content); if(!$x->Send()) { $c++; $message .= "Message could not be sent. <br/>\n"; $message .= "Mailer Error: " . $x->ErrorInfo."<br/>\n"; } else { $n++; mysql_query("DELETE FROM emailcron WHERE id=".$o->id); } } if (strlen($message)>0) { echo $message; } else { echo "Mails sent:$n; Mails Failed:$c"; } } } ?> 

cron作业的shell环境通常与loginshell不同。 这应该是原因。

还要确保你给PHP的完整path

 */5 * * * * * /usr/local/php5/bin/php -q /var/www/html/mailcron.php 

http://web.cecs.pdx.edu/~akshay/2009/11/the-cron-environment/