Hi Cristian,
I have written the code, can you pls check the code and tell me tat it’s work properly or not.
<?php
$conn = mysql_connect('localhost', 'root', '');
$database = mysql_select_db('datetime',$conn);
?>
<?php
date_default_timezone_set("UTC");
//Function to Calculate the time difference
function dateDiff($time1, $time2, $precision = 6) {
// If not numeric then convert texts to unix timestamps
if (!is_int($time1)) {
$time1 = strtotime($time1);
}
if (!is_int($time2)) {
$time2 = strtotime($time2);
}
// If time1 is bigger than time2
// Then swap time1 and time2
if ($time1 > $time2) {
$ttime = $time1;
$time1 = $time2;
$time2 = $ttime;
}
// Set up intervals and diffs arrays
$intervals = array('year','month','day','hour','minute','second');
$diffs = array();
// Loop thru all intervals
foreach ($intervals as $interval) {
// Set default diff to 0
$diffs[$interval] = 0;
// Create temp time from time1 and interval
$ttime = strtotime("+1 " . $interval, $time1);
// Loop until temp time is smaller than time2
while ($time2 >= $ttime) {
$time1 = $ttime;
$diffs[$interval]++;
// Create new temp time from time1 and interval
$ttime = strtotime("+1 " . $interval, $time1);
}
}
$count = 0;
$times = array();
// Loop thru all diffs
foreach ($diffs as $interval => $value) {
// Break if we have needed precission
if ($count >= $precision) {
break;
}
// Add value and interval
// if value is bigger than 0
if ($value > 0) {
// Add s if value is not 1
if ($value != 1) {
$interval .= "s";
}
// Add value and interval to times array
$times[] = $value . " " . $interval;
$count++;
}
}
// Return string with times
return implode(", ", $times);
}
//Function to Send mail
function sendmail($to, $remaindays){
$tomail = $to;
$from = "abc@abc.com";
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//$headers = "MIME-Version: 1.0\r\n";
//$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$mailSubject = "Bones of PA : Mail Regarding Renewal of the Membership";
$headers = "From: $from";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This mail is regarding to inform that your membership is going to be expired ".$remaindays.", so please renew the Membership soon ";
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
$ok = @mail($tomail, $mailSubject, $message, $headers);
}
?>
<?php
$date1 = date( "Y-m-d", time() );
$date2 = "2018-10-23";
$sql = 'SELECT * FROM mem_users';
$qury = mysql_query($sql);
while($row = mysql_fetch_array($qury)){
$mailid = $row['user_email'];
$date_time = $row['user_registered'];
$date = split(' ', $date_time);//echo $date[0]."<br>";
$date2 = $date[0];
$day = dateDiff($date2, $date1);
$noofdays = explode(", ", $day);
//print_r($noofdays);
$years = $noofdays[0];
$months = $noofdays[1];
$days = $noofdays[2];
if($months == 11 && $days == 0){
sendmail($mailid, $remainindays = "in a month");
//echo "<br>One month remaining for the Renew";
}
if($months == 11 && $days == 28){
sendmail($mailid, $remainindays = "in two days");
//echo "<br>Two Days remaining for the Renew";
}
//printf("<br />%d years, %d months, %d days\n", $years, $months, $days);
}
?>
I have checked this link but i was unable to know tat where to use this code in plugin
http://www.s2member.com/forums/topic/automatic-renewal-reminder/
Thanks in advance
-
This reply was modified 4 years, 2 months ago by
chidu.