简体   繁体   中英

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.

  1. The cron jobs are running (checked the logs).
  2. Invoking the script via the browser results in the emails being sent.
  3. Using SSMTP for email transport.
  4. SPF and DKIM records are in place and correct.

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. Alternatively you can just use wget to emulate a browser loading the page.

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. Adding a cd command before executing the script solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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