[quote="ajb":2mgbt1ov]Maybe I'll try to do such thing, but it's not high priority.
Here's a little chunk of code to retrieve contacts and send email. Of course it's EPESI code - not plain php.
There is no error handling. Sending won't retry on error - no error feedback, no status report. In ideal situation it's just sufficient, but in general it's not a good code.
// check date to send only once per day
$bdays_sent = Variable::get('birthdays_last_sent', false);
$today = date('Y-m-d');
if ($bdays_sent && $bdays_sent == $today) {
return;
}
// check hour - do not sent before 10 o'clock - server time.
if (date('H') < 10) {
return;
}
Variable::set('birthdays_last_sent', $today);
$crits=array('~birth_date'=> '%' . date('-m-d'));
$contacts = Utils_RecordBrowserCommon::get_records('contact', $crits);
foreach ($contacts as $c) {
if ($c['email']) {
$subject = ''; // fill it
$body = ''; // fill it
Base_MailCommon::send($c['email'], $subject, $body);
}
}
Regards,
Adam[/quote:2mgbt1ov]
Tnx a lot
If i correctly understand this code is written whit EPESI LANGUAGE and is usefull to make an EPESI SCRIPT/ADDON...it's true???
But i don't know how to install/create it and how to use...sorry but i'm not expert...
Can you help me to create a PHP version to run with CRON...i know how to use cron with PHP file...
$day = date('Y-m-d'); //set date
$sql = new mysqli("localhost", "DB_USER", "DB_PASSWORD", "EPESI_DB"); //set sql data (user, password and database)
$qry = "SELECT * FROM contact_data_1 WHERE f_activate = 1"; //take from database all contacts activated
$result = $sql->query($sql) or die($sql->error);
if($result->num_rows = 0) //control if contact list is empty
{
exit;
}
for(num_rows = 0, num_rows <$result, num_rows++) //for each concatcs...
if($f_brith_date = $day) //control if birthday is egual to today...and if yes send it a personalized mail
{
$email_body = "Dear " $row->f_first_name." ".$row->f_last_name." our staff say you happy birthday"; //mailbody (i hope it's correct...)
$to = 'f_mail';
$subject = "HAPPY BIRTHDAY";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: staff@mydomain.com";
mail($to, $subject, $email_body, $headers);
}
else{}
I create this php file but i'm sure it's not correct/perfect....can you control it and help me to finalize???
Tnx a lot for your help and for your patience