This topic is locked

Send Email based on tables query

12/11/2010 10:31:55 AM
PHPRunner General questions
M
mmponline author

I need to send a email to all the registered users in the Login table based on the fact that they want to receive e-mails:

This code seems to work.

global $dal;

$tblUsers = $dal->Table("Login");

$rs = $tblUsers->Query("SendAvailable='Yes'","");

while ($data = db_fetch_array($rs))

{

$email=$data["Email"].", ";

$from="admin@test.com";

$msg="Check testing mails";

$subject="December";

foreach($values as $field=>$value)

{

if(!IsBinaryType(GetFieldType($field)))

$msg.= $field." : ".$value."\r\n";

}

$ret=runner_mail(array('to' => $email, 'subject' => $subject,'body' => $msg, 'from'=>$from));

if(!$ret["mailed"])

echo $ret["message"]."
";

}

return true;


I, however need this mail only to go out if the value of the AddDate field in the JobsAvailable table is equal to today's date.

Something like this:

$dalTableName = $dal->Table("JobsAvailable");

$rs = $dalTableName->Query("DateDiff(now(),AddDate)>0","");;



Ps. I'm not sure what the value (varchar, date, etc)of the AddDate field should be

I don't know how to "combine" these two queries so that the result will be sending a mail to

Sending email of todays added record

to All users in the login table

That marked there Sendavailable as Yes.
Anyone that can assist I'll appreciate.
I would want to place this in a php file to use as a Cronjob to send this e-mails every day. Help on achieving this would be great!

V
velveteen 12/20/2010

You could use the if record exists sample in the visual editor to send mail. In your case, you could add conditions where SendAvailable="YES" AND Date(AddDate) = DATE(NOW()) in your query.
I used wget with windows task scheduler previously, but if you're using cron for phprunner files with security, I think you could create a blank page with guest permission and call the page. You might want to create an emailsent field if you haven't already and update the records after emails were sent though.