Hi
I am trying to make a website that sends out automatic php emails when users car tax is near it's expiry date, ideally I would the automatic emails to be sent out 2 weeks before the expiry date
I have got the info storing in a mysql database
Below is the coding I have, I am using phpmailer but I am not receiving any email?
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
?>
<html>
<title>Automatic Email</title>
<body>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['visitor_id']) && ($visitor_id = (int)$_GET['visitor_id']) > 0)
{
// query db
$result = mysql_query("SELECT * FROM visitors WHERE visitor_id = ".$visitor_id) or die(mysql_error());
// Using assoc is better in my opinion. Yes array gives you the same info, but it also gives double the info in numeric indexes, which typically are not needed.
$row = mysql_fetch_assoc($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
$sql = "SELECT * FROM visitors WHERE (visitor_tax AND visitor_mot AND visitor_insurance > DATE_SUB(CURDATE(), INTERVAL 2 WEEK)";
{
if($sql){
$to = $row['visitor_email'];
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.broadwaymediadesigns.co.uk"; // SMTP server
$mail->From = "noreply@broadwaymediadesigns.co.uk";
$mail->AddAddress("ianhaney@broadwaymediadesigns.co.uk");
$mail->Subject = "TEST EMAIL";
$mail->Body = "Hi! \n\n This is my test e-mail sent through PHPMailer.";
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
}
}
}
}
?>
</body>
</html>