title: PHPMailer not getting executed via CRON, but working via the browser. What can be the problem?
body: <p>I am trying to run PHPMailer via cron but for some reason, only the part for the token update is executed after that nothing is executed. But, if I run it via browser everything works fine. Any reason why this happens?</p>
  
  <pre><code>require_once(dirname(__DIR__)."/test/mail/PHPMailer.php");
  require_once(dirname(__DIR__)."/test/mail/SMTP.php");
  require_once(dirname(__DIR__)."/test/mail/Exception.php");
  require_once(dirname(__DIR__)."/test/db/conn.php");
  
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\SMTP;
  use PHPMailer\PHPMailer\Exception;
  </code></pre>
  
  <p>Only this part of the code is executed via cron, but in the browser, everything is executed even after this part of the code.</p>
  
  <pre><code>$sql = "SELECT * FROM customers WHERE mail_status = 0 LIMIT 100";
  
  $results = $conn-&gt;query($sql);
  
  while ($row = $results-&gt;fetch_assoc()) {
  
  $salt = rand(5, 20);
  $token = sha1($salt . sha1($salt . sha1(rand(5, 20))));
  $insert = "UPDATE customers SET token = '" . $token . "' WHERE id = '" . (int)$row['id'] . "'";
  $conn-&gt;query($insert);
  
  }
  </code></pre>
  
  <p>This part is not executed via cron:</p>
  
  <pre><code>$mail = new PHPMailer(true);
  $mail-&gt;CharSet = "UTF-8";
  $mail-&gt;isSMTP();
  $mail-&gt;Host = 'example.com';
  $mail-&gt;SMTPAuth = true;
  $mail-&gt;SMTPKeepAlive = true;
  $mail-&gt;Port = 25;
  $mail-&gt;Username = 'example@example.com';
  $mail-&gt;Password = 'example';
  $mail-&gt;setFrom('example@example.com', 'example');
  $mail-&gt;isHTML(true);
  $mail-&gt;Subject = 'example';
  $mail-&gt;AltBody = 'example';
  $mail-&gt;AddEmbeddedImage('image/3.jpg', 'logo', '3.jpg');
  
  $result = $conn-&gt;query($sql);
  
  foreach ($result as $row) {
  
  $encoded_user_id = base64_encode($row['id']);
  $link = "http://www.example.com/test/unsubscribe.php?id=". $encoded_user_id ."&amp;token=".$row['token'];
  $body = file_get_contents('contents.html');
  $body .= '&lt;div&gt;&lt;a style="text-decoration: none;color:#38aa20;" href="'.$link.'"&gt;unsubscribe&lt;/a&gt;&lt;/div&gt;';
  $mail-&gt;msgHTML($body);
    try {
        $mail-&gt;addAddress($row['email']);
    } catch (Exception $e) {
        echo 'Invalid address skipped: ' . htmlspecialchars($row['email']) . '&lt;br&gt;';
        continue;
    }
    try {
        $mail-&gt;send();
  
        echo 'Message sent to :' . htmlspecialchars($row['email']) . '&lt;br&gt;';
  
        $update = "UPDATE customers SET mail_status = 1 WHERE id= '" . (int)$row['id']  . "'";
        $conn-&gt;query($update);
  
    } catch (Exception $e) {
        echo 'Mailer Error (' . htmlspecialchars($row['email']) . ') ' . $mail-&gt;ErrorInfo . '&lt;br&gt;';
        $mail-&gt;smtp-&gt;reset();
    }
    $mail-&gt;clearAddresses();
  }
  
  $conn-&gt;close();
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Problem solved</p>