我正在运行PHP / MySQL服务器并使用cron作业定期更新我的客户以及发送自动时事通讯,发票等。但是,它似乎没有工作,因为电子邮件没有被发送。< / p>
我无法弄清楚出了什么问题。这是电子邮件脚本的伪代码:
$override_authentication = true;
require_once('../services/shared/connect.php');
$query = "SELECT * FROM `organizations`";
$orgs = mysqli_query($database,$query);
while ($org = mysqli_fetch_array($orgs)) {
// GENERATE EMAIL CONTENT HERE
// Send email to all users
$query = "SELECT `id`, `email`, `avatar`, `gender`, `phone`, `option_textalerts` FROM `users` WHERE `organization` = " . $org['id'] . " AND `option_scheduling` = 'enabled'";
$users = mysqli_query($database, $query);
while($user = mysqli_fetch_array($users)) {
$message = emailGetHeader("Submit Availability for ".date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))), $user) . $body . emailGetFooter();
$to = $user['email'];
mail($to,"Submit Availability for ".date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))),$message,emailGetMeta('Leadsheet <email@leadsheet.us>', 'Leadsheet Automailer <no-reply@leadsheet.us>'));
// If enabled, sent a text alert to the phone number on their account
if ($user['option_textalerts'] == 'availability') {
$phone = preg_replace("/[^0-9]/", "", $user['phone']);
$domains = array('txt.att.net', 'myboostmobile.com', 'sms.mycricket.com', 'tmomail.net', 'vtext.com');
foreach ($domains as $domain) {
mail($phone.'@'.$domain, "Availability Reminder",'Please submit your availability for '.date('F Y', mktime(0,0,0,date('n')+1,1,date('Y'))).' on Leadsheet', emailGetMeta('Leadsheet <txt@leadsheet.us>', 'Leadsheet Automailer <no-reply@leadsheet.us>'));
}
}
}
}
mysqli_close($database);
答案 0 :(得分:0)
看起来你错过了一个环境变量。查看phpinfo()并与您的本地环境进行比较。或者,您可以使用wget模拟加载页面的浏览器。
答案 1 :(得分:0)
咨询朋友后,我发现了答案。 cron引擎正在从根目录执行脚本,因此require_once
中的相对文件名无法解析。在执行脚本之前添加cd
命令解决了问题。