Crontab not sending php reminder email to the right person -
i try develop new feature system can send email users 1 day before reservations expired. wrote php script, , used crontab trigger execution of php file every morning. problem if compile php file, works fine, , emails sent users. when check maillog, telling
to=<useremail@email.com>, ctladdr=<blablala> (0/0), delay=00:04:12, xdelay=00:04:12, mailer=esmtp, pri=120371, relay=xxxxxxx., stat=sent (r3hmoisd031604 message accepted delivery)
but if used crontab execute same php file, mail sent root of server, not "useremail@email.com" wrote in php file.
to=<root@myserver.com>, ctladdr=<blablabla> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=30958, dsn=2.0.0, stat=sent
what can problem of it? why php file doesn't work expected crontab? can help?
my php file -- "demo.php"
require_once "defaultincludes.inc"; global $tbl_entry, $tbl_users; $current = mktime(date("h"),date("i"),0,date("m"),date("d"),date("y")); $start = $current + 12*3600; $end = $current + 40*3600; $query="select u.email, u.fullname, e.name $tbl_entry e, $tbl_users u " ." u.name = e.create_by " ." , e.end_time >= $start " ." , e.end_time <= $end "; $result= sql_query($query); $mail_list=array(); ($i=0; ($row=sql_row_keyed($result,$i));$i++) { $temp=array(); $temp[]=$row['fullname']; $temp[]=$row['email']; $temp[]=$row['name']; $mail_list[]=$temp; } ($i=0; $i<count($mail_list); $i++) { $to = $mail_list[$i][1]; $subject= "reminder of ".$mail_list[$i][2]; $body = "hi ".$mail_list[$i][0].",\n" ." reservation ".$mail_list[$i][2]." expire in 1 day"; mail($to,$subject,$body); }
crontab file -- "reminder.txt"
30 7 * * * /var/www/html/qars-vm90/demo.php
/var/www/html/qars-vm90/demo.php
will work if script marked executable. in addition you'd need shebang @ top of file tell shell file (should execute perl, php, python, ...)
i suspect email sent error message cron saying file not executable. if login root should able read message.
the simplest possible change change crontab to
30 7 * * * php /var/www/html/qars-vm90/demo.php
it's worth remembering cron's environment slight different @ command line (login shells , that)
Comments
Post a Comment