1

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 = '[email protected]';


$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: [email protected]\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.

5
  • If you output $to, $subject, $message and $headers to the screen, what are they? Commented Feb 14, 2014 at 15:18
  • Do you have a mail server set up somewhere? Commented Feb 14, 2014 at 15:18
  • try setup a page that just calls the mail() function to check that the server is set up correctly. Commented Feb 14, 2014 at 15:20
  • you should check the apache error log if you are getting a blank screen. cause this code MUST output something, if not, then there is a fatal error preventing the output. Commented Feb 14, 2014 at 15:21
  • Your error message reflects an inability to connect to the database. Please include your code that connects to the database. Commented Feb 14, 2014 at 21:35

4 Answers 4

1
$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"
Sign up to request clarification or add additional context in comments.

2 Comments

HI, thanks 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)'
You aren't logging into your MySQL server
0

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.";
    }

Comments

0
    <?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 = '[email protected]';


$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: [email protected]\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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.