Thanks for all of the replies. I'm almost there and just need a little help. Here's what I have so far...
My Crontab file has:
0 0 * * * username /path/email.php
My PHP file contains:
<?php // database connection mysqli_connect is the mysql command then followed by ('IP', 'user', 'pass', 'database') $dbc = mysqli_connect('IP', 'user', 'pass', 'database') or die('Error connecting to MySQL server.'); // MySQL code to grab the fields I need and only grab the dates that are 30 days from expiration. Tested in navicat and this code does exactly what is expected $sql = 'SELECT TABLE1.EMP_EMAIL, TABLE1.EMP_FULLNAME, TABLE2.LIS_DATE_EXP, TABLE2.CL_FNAME, TABLE2.CL_LNAME, TABLE2.LIS_NAME FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.EMP_FULLNAME = TABLE2.EMP_ID WHERE LIS_DATE_EXP = DATE_ADD(CURDATE(),INTERVAL 30 DAY)'; $result = mysqli_query ($dbc, $sql); // Define the variables and columns (loop the array) while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $email = $row["TABLE1.EMP_EMAIL"]; $fullname = $row["TABLE1.EMP_FULLNAME"]; $name = $row["TABLE2.LIS_NAME"]; $date_exp = $row["TABLE2.LIS_DATE_EXP"]; $cl_fname = $row["TABLE2.CL_FNAME"]; $cl_lname = $row["TABLE2.CL_LNAME"]; // Mail code to e-mail based on the records pulled from above code. Hoping that the syntax is correct. $to = "
[email protected], " . $email . " "; $subject = "Listing " . $name . " is about to expire!"; $message = "The Listing " . $name . " is going to expire on " . $date_exp . ". Please contact " . $cl_fname . " " . $cl_lname . " and extend the listing agreement."; $from = "
[email protected]"; $headers = "From:" . $from; mail($to,$subject,$message,$headers); } echo "Mail Sent."; ?>
The problem with my syntax is that I get an e-mail for each listing that falls in the 30 days away category, but I'm not getting the field information. So I don't get any of the information from the database. For instance below is the e-mail I get.
The Listing is going to expire on . Please contact and extend the listing agreement.