简体   繁体   English

Cron正在运行,但未发送电子邮件

[英]Crons are running but email not sent out

I am running a PHP/MySQL server and am using cron jobs to periodically update my customers as well as send automated newsletters, invoices, etc. However, it does not appear to be working, as emails are not getting sent. 我正在运行PHP / MySQL服务器,并使用cron作业来定期更新我的客户以及发送自动新闻通讯,发票等。但是,由于电子邮件未发送,它似乎不起作用。

  1. The cron jobs are running (checked the logs). cron作业正在运行(已检查日志)。
  2. Invoking the script via the browser results in the emails being sent. 通过浏览器调用脚本会导致发送电子邮件。
  3. Using SSMTP for email transport. 使用SSMTP进行电子邮件传输。
  4. SPF and DKIM records are in place and correct. SPF和DKIM记录到位且正确。

I cannot figure out what is going wrong. 我无法弄清楚出了什么问题。 Here is pseudocode of the email script: 这是电子邮件脚本的伪代码:

$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);

It looks like you are missing an environment variable. 看来您缺少环境变量。 look at phpinfo() and compare with your local environment. 查看phpinfo()并与您的本地环境进行比较。 Alternatively you can just use wget to emulate a browser loading the page. 另外,您可以只使用wget模拟浏览器加载页面。

After consulting a friend, I discovered the answer. 向朋友咨询后,我找到了答案。 The cron engine was executing the script from the root directory, so the relative file name in the require_once wasn't resolving. cron引擎正在从根目录执行脚本,因此require_once的相对文件名无法解析。 Adding a cd command before executing the script solved the issue. 在执行脚本之前添加cd命令可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM