我有一个使用php mail发送电子邮件的php文件。我设置了一个foreach循环,以便从表中提取数据并为每行发送一封电子邮件。我能够写电子邮件,然后回显它,以验证它看起来是正确的,并提取正确的数据。我遇到的问题是,当我创建cron作业(在cpanel中)时,它会返回一个500内部服务器错误。如果我从文件中移除所有数据库连接,那么它将正常工作,因此我知道cron作业设置正确。
这是我的php文件:
<?php
include('config/route.php');
$agent = "SELECT * FROM the_agent WHERE status = 1";
$agentInfo = $obj->queryResult($agent);
foreach($agentInfo as $value){
$to = 'my email';
$subject = 'Your Match Request';
$message = "<p>Hey ".$value['name']."!</p>
<p>Here is your weekly report.</p>
<p>You had ____ full job description/profile views from the following travelers: </p>
<p>(List of Travelers first names and disciplines)</p>
<p>And ____ applications from: </p>
<p>(List of travelers full names and disciplines)</p>
<p>This weeks matches include: </p>
<p>(List of matches)</p>
<p>I hope you had a great week! Don't forget to follow up with your applicants today if you haven't done so already.</p>
<p>Have an awesome weekend!</p>
";
$headers = array(
'From: email',
'Content-type: text/html; charset=iso-8859-1'
);
mail($to, $subject, $message,implode("\r\n",$headers));
}
?>我的php文件中有没有什么地方遗漏了/做错了?关于cron作业和数据库连接,有没有什么我不知道的?这是我第一次处理cron作业,因此任何意见或建议都将非常感谢。谢谢您抽时间见我。
发布于 2020-08-06 05:29:23
您的代码可能依赖于环境变量来设置数据库连接,而这在cron作业中是不可用的。
$ export
显示当前环境变量
在不了解数据库的情况下,很难确定需要什么,但您应该能够在cron文件的顶部执行以下操作来填充环境变量:
ORACLE_SID=testdb 0 7*** php emailscript.php
https://stackoverflow.com/questions/63273650
复制相似问题