Delay PHP email in cron

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lilnicky37
Forum Newbie
Posts: 10
Joined: Wed Apr 14, 2010 11:56 am

Delay PHP email in cron

Post by lilnicky37 »

Hello All,

I hope I'm posting this in the correct place. I'm currently using cron to run a PHP script daily. The purpose of the script is to check a MYSQL database, and if it finds certain entries older than 2 months, it will send an email to the address associated with the entry. What I want to do is, once this email has been sent, delay the script from sending the email until ANOTHER 2 months has passed (so a total of 4 months from the timestamp in the database).
Is this something I can accomplish through PHP script? Or is there a way for me to configure cron to recognize this?
The current script is below:

Code: Select all

<?php 
mysql_connect("localhost","xxxxxxxx","xxxxxxx") or die(mysql_error());
mysql_select_db("xxxxxxxx") or die(mysql_error());
$check = mysql_query("SELECT * FROM xxxx WHERE date < DATE_SUB(NOW(), INTERVAL 2 MONTH)");
while($result = mysql_fetch_array($check)) {
$user = $result['username'];
$book = $result['title'];
$thedate = $result['date'];
$check1 = mysql_query("SELECT * FROM users WHERE username = '$user'");
while($result1 = mysql_fetch_array($check1)) {
$email = $result1['email'];
$EmailFrom = "xxxxxxxxxxx";
$Subject = "xxxxxxxx";

$msg = "xxxxxxxxxxxxxxxxxxxx";

mail($email,$Subject,$msg,"From: $EmailFrom");
}
}
?>
Thanks
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Delay PHP email in cron

Post by AbraCadaver »

Update the DB. Something like:

[text]UPDATE xxxx SET `date` = NOW() WHERE `username` = ' $user'[/text]
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply