I need to send an email to user to notify them of reports expiring.
Code I have set up so far but it is not sending the email nor are there any error messages through the browser, can anyone tell me where I am going wrong.
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include 'connect_mobile.php';
/*
$today = $_POST['reportdate'];
$name = $_POST['engineername'];
$engineerid = $_POST['engineerid'];
$engineeremail = $_POST['engineeremail'];
*/
$today = '2013-03-14';
$name = 'John Wheeler';
$engineerid = '130';
$engineeremail = 'jwheating@gmail.com';
$to = $engineeremail;
$subject = "Report expiring 30 days";
// give your message the starting string
$message = 'Greetings '.$name.',
you are receiving this email as a reminder that the following reports expire in 30 days:
<table style="width: 80%;">
<tr>
<td>Report No</td>
<td>Client</td>
<td>Property Address</td>
<td>Address</td>
<td>Address</td>
<td>Postcode</td>
<td>Expiry Date</td>
</tr>
'
$query = "SELECT * FROM certifs WHERE currentdate = '"$today"' AND userid = '"$engineerid"'"
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$message .= " <tr>";
$message .= " <td>".$row['certno']."</td>";
$message .= " <td>".$row['clientcompany']."</td>";
$message .= " <td>".$row['propertyadd1']."</td>";
$message .= " <td>".$row['propertyadd2']."</td>";
$message .= " <td>".$row['propertyadd3']."</td>";
$message .= " <td>".$row['propertypostcode']."</td>";
$message .= " <td>".$row['currentdate']."</td>";
$message .= " </tr>";
// then update the message with the ending
$message .= "
</table>
Thank you,
John Wheeler Gas Reports."
}
//-- The headers will let us send HTML code as an email
$headers = "From: support@john-wheeler.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//-- if mail gets sent, return true, else return false.
if (mail($to,$subject,$message,$headers))
{
$response = array('mail' => true);
}
else
{
$response = array('mail' => false);
}
echo json_encode($response);
}
?>
HI, thank you all for pointing out my silly mistakes, I corrected the syntax now at least I get an error message.
Warning: mysql_query(): Access denied for 'user'johnny'@'localhost' (using password:NO) in /var/www/vhosts/vvps-835282.dailyvps.co.uk/john-wheeler.co.uk/mobilereports/reportexpires.php on line 35 Warning: mysql_query(): A link to the server could not be established in /var/www/vhosts/vvps-835282.dailyvps.co.uk/john-wheeler.co.uk/mobilereports/reportexpires.php on line 35 Access denied for user 'johnny'@'localhost' (using password: NO)
How the hell do I format code? Sorry first time on StackOverflow.
The code is on my VPS, I have other mail scripts running fine using mail.
$message = 'Greetings '.$name.',
you are receiving this email as a reminder that the following reports expire in 30 days:
<table style="width: 80%;">
<tr>
<td>Report No</td>
<td>Client</td>
<td>Property Address</td>
<td>Address</td>
<td>Address</td>
<td>Postcode</td>
<td>Expiry Date</td>
</tr>
'
You're missing a ;
at the end of this. You aren't getting any error messages as it's a syntax error.
and at the end of this line
$query = "SELECT * FROM certifs WHERE currentdate = $today AND userid = $engineerid"
Try this, You have some errors in
$query = "SELECT * FROM certifs WHERE currentdate = '"$today"' AND userid = '"$engineerid"'"
....^
Missed to add ;
in some places, I have corrected the same and use below one,
Replace:
// give your message the starting string
$message = 'Greetings '.$name.',
you are receiving this email as a reminder that the following reports expire in 30 days:
<table style="width: 80%;">
<tr>
<td>Report No</td>
<td>Client</td>
<td>Property Address</td>
<td>Address</td>
<td>Address</td>
<td>Postcode</td>
<td>Expiry Date</td>
</tr>
';
$query = "SELECT * FROM certifs WHERE currentdate = '$today' AND userid = '$engineerid'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$message .= " <tr>";
$message .= " <td>".$row['certno']."</td>";
$message .= " <td>".$row['clientcompany']."</td>";
$message .= " <td>".$row['propertyadd1']."</td>";
$message .= " <td>".$row['propertyadd2']."</td>";
$message .= " <td>".$row['propertyadd3']."</td>";
$message .= " <td>".$row['propertypostcode']."</td>";
$message .= " <td>".$row['currentdate']."</td>";
$message .= " </tr>";
// then update the message with the ending
$message .= "
</table>
Thank you,
John Wheeler Gas Reports.";
}
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
include 'connect_mobile.php';
/*
$today = $_POST['reportdate'];
$name = $_POST['engineername'];
$engineerid = $_POST['engineerid'];
$engineeremail = $_POST['engineeremail'];
*/
$today = '2013-03-14';
$name = 'John Wheeler';
$engineerid = '130';
$engineeremail = 'jwheating@gmail.com';
$to = $engineeremail;
$subject = "Report expiring 30 days";
// give your message the starting string
$message = 'Greetings '.$name.',
you are receiving this email as a reminder that the following reports expire in 30 days:
<table style="width: 80%;">
<tr>
<td>Report No</td>
<td>Client</td>
<td>Property Address</td>
<td>Address</td>
<td>Address</td>
<td>Postcode</td>
<td>Expiry Date</td>
</tr>
';
$query = "SELECT * FROM certifs WHERE currentdate = '".$today."' AND userid = '".$engineerid."'";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
$message .= " <tr>";
$message .= " <td>".$row['certno']."</td>";
$message .= " <td>".$row['clientcompany']."</td>";
$message .= " <td>".$row['propertyadd1']."</td>";
$message .= " <td>".$row['propertyadd2']."</td>";
$message .= " <td>".$row['propertyadd3']."</td>";
$message .= " <td>".$row['propertypostcode']."</td>";
$message .= " <td>".$row['currentdate']."</td>";
$message .= " </tr>";
// then update the message with the ending
$message .= "
</table>
Thank you,
John Wheeler Gas Reports.";
}
//-- The headers will let us send HTML code as an email
$headers = "From: support@john-wheeler.co.uk\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//-- if mail gets sent, return true, else return false.
if (mail($to,$subject,$message,$headers))
{
$response = array('mail' => true);
}
else
{
$response = array('mail' => false);
}
echo json_encode($response);
?>
you have a lot of syntax problems... maybe but that.
if you have a mail server setup then add this to your php.ini file
sendmail_path = /usr/sbin/sendmail -t -i
for Linux/Unix systems
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.