I have a php file that is triggered by a cron job to send an email to a database of people every 7 days, for 9 weeks from their sign up date. We need to modify the file to make the intervals different than every seven days. We need to be able to define the variables like this, at the top of the php file:
$day1 = 10000 seconds
$day2 = 50000000 seconds
$day3 = 5000000000 seconds,
etc
Is there an easy way to incorporate this into the file attached to this forum post.
<?
// Configuration here
/---------------------------------------------------------------------------------- /
set_time_limit(0);
include ("lists/config/config.php");
$conn = mysql_connect($database_host,$database_user,$database_password);
if (!$conn) die ("Database configuration wrong.");
mysql_select_db($database_name);
// Read the emails we need to send
$sql = "select * from config order by name asc";
$res = mysql_query($sql);
while (list($key,$val,$title)=mysql_fetch_row($res)) {
$emailData[$key] = $val;
$emailTitle[$key] = $title;
}
$now = time();
$sql = "select id,email,entered,sent from phplist_user_user";
$res = mysql_query($sql);
while (list($uid,$email,$time,$sent,$subject)=mysql_fetch_row($res)) {
$ntime = strtotime($time);
$diff = $now-$ntime;
echo ($diff/604800);
// echo round($diff/86400) . ", $email, $sent <br>";
// Check if it's a positive value
if ($diff>0) {
//echo $diff."<br>";
// Check which email to send
//86400 = 24 hours in seconds
//604800 = 7 days
if ($diff>604800) {
//mailCount is the days between signup
$mailCount = round($diff/604800);
// Check if sent counter is smaller. if it's then send an email and update the counter
if ($mailCount>$sent) {
$getName = mysql_query("SELECT * FROM phplist_user_user_attribute WHERE userid ='$uid' AND attributeid='1'");
$getName_row = mysql_fetch_assoc($getName);
// Check if it's allready past 7 days or not
if ($mailCount<=9) {
$sql = "update phplist_user_user set sent='$mailCount' where id='$uid'";
mysql_query($sql);
$to = $email;
$message = $emailData["mail".trim($mailCount)];
$subject = $emailTitle["mail".trim($mailCount)];
$message = str_replace("[firstname]", ucfirst($getName_row['value']), $message);
// $msg = str_replace("[firstname]",
//send the mail
include 'mail2.php';
// $url = "mail.php?to=$to&subject=".urlencode($subject)."&from=$from&msg=".urlencode($msg);
// $result = implode("",file($url));
}
}
}
}
}
?>