1

I am using swiftmailer 6.0. When I run that file from url its work perfect but when I run that file from cron job i stuck in errors like very first error is ??

PHP Parse error:  syntax error, unexpected '?', expecting

when I remove one ? than it give me another file and line number which has same ?? I replace all ?? into ?: than I got stuck into another error which is about try,catch & finally in 4 files the didn't declare catch after try they declace finally directly.

PHP Parse error:  syntax error, unexpected 'finally' (T_STRING)

After all the effort I search this issue on stackoverflow and follow this annswer but didn't find any solution and update swiftmail to 6.0.1 but didn't help me out. this is my all code.

require 'Path to/autoload.php';
// //=======  SwiftMailer
$transport = (new Swift_SmtpTransport('sever', port,'ssl'))
->setUsername($smtp_email)
 ->setPassword($smtp_password)
;
$mailer = new Swift_Mailer($transport);
$smtp_message = (new Swift_Message($subject))
  ->setFrom(['example@any.com' => 'Test Title'])
  ->setTo($to)
  ->setBody($message,'text/html')
;
 $result = $mailer->send($smtp_message);

Help me out i supend more than 3 hours on it.

Wesley Smith
  • 19,401
  • 22
  • 85
  • 133
The IRF
  • 470
  • 3
  • 13
  • 1
    Offhand, I suspect that the version of php your web server uses is a newer version while the version used by your cron (PHP-cli) is a different version. Try running `echo phpinfo()` from your web server and running `php -v` from your console and comparing the version output – Wesley Smith Oct 24 '20 at 17:10
  • `??` or the "Null Coalescing Operator" was introduced in php 7. I suspect your cli uses a version before that. – Wesley Smith Oct 24 '20 at 17:12
  • The `unexpected 'finally'` error would seem to indicate your cli version is 5.4 or lower, which is quite old if that's right – Wesley Smith Oct 24 '20 at 17:14
  • I use `echo phpinfo();` It returns `7.1.14` but how can check my cron version? – The IRF Oct 24 '20 at 17:15
  • 1
    open your console where the cron runs and run `php -v` – Wesley Smith Oct 24 '20 at 17:16
  • I didn't find the console to run command – The IRF Oct 24 '20 at 17:28
  • What OS is the machine on which the cron runs? – Wesley Smith Oct 24 '20 at 17:30
  • I am running cron job from cpanel of hostgator – The IRF Oct 24 '20 at 17:31
  • 1
    See https://www.hostgator.com/help/article/linux-shell-basics – Wesley Smith Oct 24 '20 at 17:32
  • Alternatively, cPanel may have a terminal/console launcher button somewhere in the ui, Im not certain. – Wesley Smith Oct 24 '20 at 17:34
  • Can you give the updated command line which restrict the cron job to run in php7+ like `/usr/local/bin/ea-php70/home/username/public_html/test_crone.php` – The IRF Oct 24 '20 at 17:53
  • 1
    There is no updated command per se, if you run `php -v` from a terminal on that server and it says you have a version < 7, you'll need to update the php-cli on that server to a version that is >= 7. You still havent told us what OS you're running or what the output of `php -v` says but you should be able to google something like `upgrade php-cli from X to 7 on Y OS with hostgator` (filling in X and Y with those values) and get some advice on the steps specific to your situation – Wesley Smith Oct 24 '20 at 19:09
  • I updated the php-cli version but didn't receive the email – The IRF Oct 26 '20 at 13:37
  • See this question for debugging help with swift mailer https://stackoverflow.com/questions/19366289/swift-mailer-cant-send-mail-and-cant-find-error-logs – Wesley Smith Oct 26 '20 at 22:19
  • But after alots of tries I am moving to phpMailer and it works – The IRF Oct 31 '20 at 14:29

0 Answers0