badger1010 Posted October 2, 2015 Share Posted October 2, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/298407-using-db-query-results-to-send-email/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.