Forum Moderators: coopster

Message Too Old, No Replies

Creating E-Mail Alerts

         

rjbearcan

6:24 am on Sep 25, 2005 (gmt 0)

10+ Year Member



I've been looking around to see how I can create a script for e-mail notifications with no luck. Does anyone know where I can find a tutorial on this?

R e b r a n d t

9:26 am on Sep 25, 2005 (gmt 0)



First you will need a php mail [php.net] functions and then (if needed) some time scheduling: cron [google.com] under *nix or Ms Scheduler [google.com] under windows.

Basicaly you write a script, that uses mail function to send desired notification on desired trigger. Then you make script run every minute (or second, or 5 minutes) with a cron/task scheduler.

Sometimes you dont need a cron/task scheduler - you can run your script with a browser...

dmmh

12:00 pm on Sep 25, 2005 (gmt 0)

10+ Year Member



function func_mass_email_manual($emails, $usernames, $subject,$message_mail){
foreach ($emails as $to){

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-15\r\n";
$headers .= "From: Site.com < notify@site.com >\r\n";
$message .= "<div align=\"center\">\n";
$css = file_get_contents("http://www.site.com/main_mail.css");
$header_img = file_get_contents("http://www.site.com/includes/header.php");
$message .= "<style>\n<!--\n ".$css." \n-->\n</style>\n";
$message .= "<table width=\"100%\" border=\"0\" class=\"some_class\">\n";
$message .= "<tr>\n";
$message .= "<td valign=\"top\">\n";
$message .= "<br/>\n";
$message .= "<div align=\"center\">\n";
$message .= "".$header_img."\n";
$message .= "<br/>";
$message .= "<table width=\"90%\" border=\"0\" class=\"some_other_class\">\n";
$message .= "<tr>\n";
$message .= "<td valign=\"top\">\n";
$message .= "<table width=\"100%\" border=\"0\" class=\"table\" id=\"right\">\n";
$message .= "<tr>\n";
$message .= "<td class=\"col\"><div align=\"left\">".$message_mail."</div></td>\n";
$message .= "</tr>\n";
$message .= "</table>\n";
$message .= "</td>\n";
$message .= "</tr>\n";
$message .= "</table>\n";
$message .= "<br/><font size=\"1\" face=\"Arial, Helvetica, sans-serif\"><strong>Note: this is an automated message, email messages returned to this adress will not be read.</strong></font>\n";
$message .= "</div>\n";
$message .= "</td>\n";
$message .= "</tr>\n";
$message .= "</table>\n";
$message .= "</div>\n";
/* mail it */
mail($to, $subject, $message, $headers);
}
}

Then call it somewhere like:

func_mass_email_manual($emails, $usernames, 'A test message','You are receving this message because bla bla bla');
$emails should be an array of email adresses, $username an array of corresponding usernames, both containing at least 1 value ofcourse :)