| | #1 |
| Mini Mac | Help with an automatic php mailerRight guys I need to set up an automatic email system that can email a customer 48 hours after they have their appointment to get their tyres fitted. So far this is what I've come up with. -I need to set up a cron job to run the script once a day. Code: <?php
//include the connection file
require_once('connection.php');
$query = "SELECT email FROM table WHERE TO_DAYS(date)=TO_DAYS(NOW())-2";
$object=mysql_fetch_object($query);
mail($object->emailid,'Subject here','Message here'); // more info on this function: http://uk.php.net/manual/en/function.mail.php
echo $object->emailid; // this will echo the users email ID as corresponding to your database. $object-> simply is calling the fields it can corresponding to the query we made, such as $object->emailid;
?>
Just want tips on whether I'm on the right track. These are just snips of code I've found and mashed together. Cheers
__________________ Currently: ![]() My Sites Free Nintendo DSi www.macbook4u.co.uk Free Android Free PS3 Games open spoiler to see what im doing Spoiler Last edited by beezer123; 02-02-10 at 09:28 AM.. |
| Offline | |
| | #2 |
| Mini Mac | In fact scrap that. I think I've come up with a better code. Code: <?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();
}
?>
__________________ Currently: ![]() My Sites Free Nintendo DSi www.macbook4u.co.uk Free Android Free PS3 Games open spoiler to see what im doing Spoiler |
| Offline | |
| | #3 |
| iBook Join Date: Oct 2007 Location: Glasgow
Posts: 2,000
Thanks: 323
Thanked 538 Times in 428 Posts
![]() ![]() ![]() | You could have a look at this tutorial for creating a secure mailer script, and adapt it to what you need; PHP Mail Form: Secure and Protected » tutorialtastic.co.uk Did you do much PHP on your course - actually, PM on it's way - meant to do that the other day.
__________________ Received about £1600 worth so far! Spoiler ![]() |
| Online | |
| | #4 | |
| Mini Mac | Quote:
I did absolutely no PHP during my course and I'm just trying to self teach myself. I think you did send me a PM but I may be wrong, haven't had a chance to reply if it was you. I'll reply now.
__________________ Currently: ![]() My Sites Free Nintendo DSi www.macbook4u.co.uk Free Android Free PS3 Games open spoiler to see what im doing Spoiler | |
| Offline | |
![]() |
| Thread Tools | |
| |