pioneerx01 Posted August 11, 2016 Share Posted August 11, 2016 (edited) I have been using SwiftMailer for few years now to sent confirmation emails upon registration and password recovery emails is requested; with great success. I have first stared to code the page and manually triggering it by going to the URL directly with my browser. Entire thing runs in little under one second, completes in full, no error and all intended people get emails as they should. Here is the relevant code: require '../../scripts/swift-mailer/lib/swift_required.php'; require '../../scripts/swift-mailer/confirmation_smtp.php'; // Create the Mailer using your created Transport $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance() ->setFrom(array("confirmation@mydomain.com")) ->setTo("me@gmail.com") ->setBcc(array("archive@mydomain.com")) ->setReplyTo(array("confirmation@mydomain.com")) ->setSubject("Daily Update") ->setBody($body, 'text/html'); // Send the Message $result = $mailer->send($message); And the confirmation_smtp.php file is: $transport = Swift_SmtpTransport::newInstance('www.mydomain.com', 465, 'ssl') ->setUsername('confirmation@mydomain.com') ->setPassword('password'); My "send to" email address is currently set to my gmail address for testing purposes. Right now I am trying to use CRON jobs to send handful of emails to few people every 24 hours if certain conditions are met. I have added the command line in "php /home/username/../../../emails.php" and it runs as scheduled, I get no errors in the logs. As you can see I send a BCC to my local email, archive@mydomain.com. With CRON job I get the BCC email to my local email address (archive@mydomain.com) with the email structure as it should be, as well as "To" address showing as my gmail account in headers. However, my gmail account gets no messages with my code being triggered by CRON job itself (I have checked spam). If, however, I manually type in the URL where the same code is stored, it runs, and only then I do get the email to gmail (or yahoo, or any other external email). I am not sure why CRON job is not sending emails to outside domains, just local ones. I have shared business hosting with HostGator, with dedicated IP address, cPanel control, and correctly configured Email Authentication records for mailing. Any thoughts? Thanks Edited August 11, 2016 by pioneerx01 Quote Link to comment https://forums.phpfreaks.com/topic/301841-problem-with-swiftmailer-and-cron-jobs/ Share on other sites More sharing options...
pioneerx01 Posted August 13, 2016 Author Share Posted August 13, 2016 Not even a guess? Quote Link to comment https://forums.phpfreaks.com/topic/301841-problem-with-swiftmailer-and-cron-jobs/#findComment-1536080 Share on other sites More sharing options...
requinix Posted August 13, 2016 Share Posted August 13, 2016 Do you have access to the SMTP server logs? Or your hosting provider? Can you confirm that the server is receiving an email message as expected? Alternatively you could (maybe) set up a local sendmail that logs everything, then send your email through that and compare the messages when sent through cron and the browser. In other words, gather information. Confirm that stuff is working at it should at each step after your code. Compare what you see with and without cron. Quote Link to comment https://forums.phpfreaks.com/topic/301841-problem-with-swiftmailer-and-cron-jobs/#findComment-1536081 Share on other sites More sharing options...
Jacques1 Posted August 13, 2016 Share Posted August 13, 2016 And under which account do the cronjobs run? The webserver account (e. g. www-data)? Quote Link to comment https://forums.phpfreaks.com/topic/301841-problem-with-swiftmailer-and-cron-jobs/#findComment-1536082 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.