Jump to content

using db query results to send email


badger1010

Recommended Posts

Firstly I'd like to say I'm not a coder and I'm new to this forum, so I apologise in advance for any silly noob errors or if I have not followed appropriate forum etiquette.
 
I have a mysql database to store customer details including the date of an annual examination.
 
The customers appreciate being reminded about the exam date before it is due, so I want to query the db (about a month in advance) and if any date matches are found, pull out the necessary details and use them to populate and automatically send a reminder email.
 
I thought that if I could find a php script I could use a cron job to run the query once a day, some days there may be no matches but other days there could be 6 or more.
 
However, although I've managed to find out how the run a query on the db, I have no idea how to use the results to send the email.
 
Is anyone able to offer some pointers as to how I can achieve the desired results?
 
This the code I have to run the query and return any matches:
<?php
$servername = "localhost";
$username = "root";
$password = "*******";
$dbname = "*******";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM customer_details WHERE exam_date = DATE_ADD(CURDATE(), INTERVAL 29 DAY)";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Customer name: " . $row["customer_name"]. "Email: " . $row["email_address"]. "Examination date: " . $row["exam_date"]. "Serial number: " . $row["ser_no"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

Thanks in advance for any help you may be able to offer.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.