简体   繁体   中英

send email automatically before the expire date

In my application, I need the email to send automatically to the registered clients as the membership is expiring, is cron job is the only solution to send the mail automatically, I tried cron job, where i am able to send the mail for scheduled time but how will i take the respective expiry date of the client and trigger the mail

    <?php

// Set this to your timezone
date_default_timezone_set('asia/kolkata');

// Start at 8:00 AM (24-hour time)
$startTime = mktime(8, 0, 0);

// End at 5:00 PM (24-hour time)
$endTime = mktime(17, 0, 0);


$currentTime = time();

// Do not send the email if it is outside of the allowed hours
if($currentTime < $startTime || $currentTime > $endTime)
{
    print('Not sending an email after hours.');
    die();
}

// Get the current day of the week as an index (0=Sunday, 6=Saturday)
$dayOfWeek = date('w');

// Do not send the email on weekends
if($dayOfWeek == 0 || $dayOfWeek == 6)
{
    print('Not sending an email on the weekends.');
    die();
}

// Info of person to receive the tests
define('TO_EMAIL',      'ramya.krish7@gmail.com');
define('TO_NAME',       'ramya');

// Info of person sending the tests
define('FROM_EMAIL',    'webmaster@serversendingtests.com');
define('FROM_NAME', 'Email Tester');

// Example: 8:00 am on 1 Nov 2010
$subject = 'Test: ' . date('g:i a \o\n j M Y');

$message = 'This email was automatically generated. Please send an email to yourusername@youremailprovider.com if you would like to disable these automated tests.';

$result = mail(TO_NAME . ' <' . TO_EMAIL . '>', $subject, $message, 'From: ' . FROM_NAME . ' <' . FROM_EMAIL . '>');
var_dump($result)

Suppose you call the file sendmail.php through cron job, then your code should contain : (since you have not provide any table structure)

<?php

//get the result from clients table


//check whether clients expiry date is expired or not


// if yes then

//then said mail

//else

//do nothing


?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM