Cron Job PHP Foreach Only Sends Out ONE Email/Runs ONE Row -
i trying run cron job executes next php code:
<?php require 'core/init.php'; $freq = "1day"; $camp = $users->get_campaigns($freq); foreach($camp $val) { $data['customer'] = $val['thename']; $data['companyname'] = $val['company']; $data['email'] = $val['reply_to']; if($val['defaultc'] == "1") { $phrase = $val['1']; } elseif($val['defaultc'] == "2") { $phrase = $val['2']; } elseif($val['defaultc'] == "3") { $phrase = $val['3']; } $placeholders = array("{customer}", "{companyname}", "{email}"); $new_member_file = str_replace($placeholders, $data, $phrase); $headers = "from: ".$val['reply_to']."\r\n"; $headers .= "reply-to: ".$val['reply_to']."\r\n"; $headers .= "mime-version: 1.0\r\n"; $headers .= "content-type: text/html; charset=iso-8859-1\r\n"; $message = "<html><head><style type='text/css'>body { font-family: arial, sans-serif; }</style></head><body>"; $message .= "".$new_member_file."</body></html>"; mail($val['theemail'], $val['sub1'], $message, $headers,'-f'.$val['reply_to'].''); $users->email_sent($user_id); } ?>
if access file straight via browser, works perfect. however, if running via cron job, execute foreach code once...meaning pulls first row out of mysql database , sends 1 email, when should pulling multiple rows , sending multiple emails.
i have no clue why happening - have tried searching reason why happening no luck.
anybody have ideas?
get_campaigns() function in script using $_post superglobals - cannot via cron jobs. removed $_post superglobals , cron script executed flawlessly.
php cron
No comments:
Post a Comment