Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP/Cronjob Mail Function [duplicate]

Tags:

php

email

cron

I have a website on the web, and I want to use CronJob, to send newsletters every Monday. Now, I'm using PHP to do this, and I'm stuck. I have a mail() function, that sends mail, to every address stated in a file.

Here is my CronJob file. I changed the date to everyday, just for debugging.

0 9 * * *   php -f /home/a4770799/public_html/mail/newsletter.php

Here is my PHP file. This is the whole file.

<?php
  $subject = "Weekly Newsletter";
  $msg = "This is a weekly newsletter debugging test.";
  $headers = "From: [email protected]" . "\r\n" .
             "Reply-To: [email protected]" . "\r\n";
  $linesofmail = file("mail_address_list.txt");
  foreach ($linesofmail as $line_num => $line) {
    mail ($line, $subject, $msg, $headers);
  }
?>

What might be the problem here? I would love it, if someone would explain the problem to me, instead of just giving me a piece of code.

like image 934
FoxInFlame Avatar asked Jan 30 '26 01:01

FoxInFlame


1 Answers

You can check out the error log. It can be problem reading the mail_address_list.txt or php mail error.

Check this out to prevent mails moving to junk.

like image 135
Nisha Avatar answered Feb 01 '26 15:02

Nisha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!