2014-05-12 41 views
0

在我的應用程序中,當成員資格到期時,我需要電子郵件自動發送到註冊客戶端,cron作業是自動發送郵件的唯一解決方案,我嘗試了cron job,在哪裏我能夠發送郵件的預定時間,但我將如何把客戶端的相應的到期日,並觸發郵件在過期日期前自動發送郵件

<?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',  '[email protected]'); 
define('TO_NAME',  'ramya'); 

// Info of person sending the tests 
define('FROM_EMAIL', '[email protected]'); 
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 [email protected] 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) 
+0

在您的cron文件中爲成員資格過期的客戶啓動查詢,然後根據該更新您的查詢 –

+0

@RakeshShetty謝謝,這是我第一次遇到cron job,請您提供示例cron文件並解釋我如何解決這個問題。 – Ramya

+0

@Ramya你說過你已經創建了一個cron文件來爲你的問題添加這個代碼 –

回答

0

假設你通過打電話cron作業文件sendmail.php,那麼你的代碼應包含: (因爲您還沒有提供任何表格結構)

<?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 


?> 
+0

因此每一分鐘這個腳本必須運行? – Ramya

+0

@Ramya這個腳本應該運行取決於你在cron job中設置的時間 –

相關問題