Auto Email system
Posted: Tue Feb 02, 2010 4:25 am
Hi all,
First post here as I couldn't find an Introduction section.
Anyways here's the task I've been set out to achieve. I want to have a mailing script that can query a database and pull out clients who have had their appointment 48 hours previous so that it will automatically email them asking them to provide feedback on their experience.
Here's the code I've got so far. Hopefully someone may be able to advise on whether it's along the correct lines. I haven't run this script at all yet as I wanted to get it checked out before I potentially cock up and send emails to everyone in our database.
Thanks for all help in advance.
BTW the name's Peter
First post here as I couldn't find an Introduction section.
Anyways here's the task I've been set out to achieve. I want to have a mailing script that can query a database and pull out clients who have had their appointment 48 hours previous so that it will automatically email them asking them to provide feedback on their experience.
Here's the code I've got so far. Hopefully someone may be able to advise on whether it's along the correct lines. I haven't run this script at all yet as I wanted to get it checked out before I potentially cock up and send emails to everyone in our database.
Thanks for all help in advance.
BTW the name's Peter
Code: Select all
<?php
#include PHPMailer class and database connection
include("class.phpmailer.php");
include("db.php");
#remove slashes from content
$html = stripslashes($_POST["html"]);
$plain = stripslashes($_POST["plain"]);
#initiate PHPMailer class
$mail = new PHPMailer();
#set the from e-mail address
$mail->From = "email@domain.co.uk";
#set the from name
$mail->FromName = "Company Name";
#set the e-mail type to HTML
$mail->IsHTML(true);
#the subject of the email
$mail->Subject = "Our Newsletter";
#the HTML content of the email
$mail->Body = $html;
#the plain text version
$mail->AltBody = $plain;
#loop through e-mail addresses
$query = "SELECT email FROM table WHERE TO_DAYS(date)=TO_DAYS(NOW())-2";
$result = mysql_db_query ("$databasename", $query);
while ($myrow = mysql_fetch_array($result)){
#add applicable address as the recipient
$mail->AddAddress($myrow["fldEmail"]);
#sends the email
$mail->Send();
#clears the recipient address
$mail->ClearAddresses();
}
?>