1
我很難搞清楚如何在我的expired_account()函數中多次使用我的sendemail()函數,具體取決於它發現的內容。首先它會檢查8天內到期的帳戶,發送電子郵件,然後檢查1天,發送電子郵件,然後檢查過期帳戶 - 發送電子郵件。我的sendemail函數多次使用返回redeclare或undefine var錯誤
8天的第一次檢查工程..電子郵件與沒有錯誤發送,但任何其他sendemail()返回一個錯誤,或者是
include_once:
Notice: Undefined variable: mail in C:\www\dev\common.inc on line 4585 Fatal error: Call to a member function setFrom() on a non-object in C:\www\dev\common.inc on line 4585
或當我改變include_once只是包括:
Fatal error: Cannot redeclare PHPMailerAutoload() (previously declared in C:\www\dev\phpmailer\PHPMailerAutoload.php:24) in C:\www\dev\phpmailer\PHPMailerAutoload.php on line 31
我sendemail功能:
function sendemail($wordwrap=50, $html=true, $to, $cc='', $cc2='', $cc3='', $subject, $body) {
include_once "phpmailer/phpmailer.inc";
global $systememail;
$fromname = "System Mail";
$mail->setFrom($systememail, $fromname);
$mail->addAddress($to);
if ($cc != "")
$mail->addCC($cc); //CC
if ($cc2 != "")
$mail->addCC($cc2); //CC
if ($cc3 != "")
$mail->addCC($cc3); //CC
$mail->WordWrap = $wordwrap; // Set word wrap to 50 characters
$mail->isHTML($html); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->send()) {
$maxTries = 3;
for ($try=1; $try<=$maxTries; $try++) {
usleep(5000);
if ($mail->send()) {
break;
}
if ($try >= 3) {
exit;
}
}
}
}
我的代碼執行sendemail()函數:
if ($daysleft == 8) {
//do this for 8 days left before contract ends
$subject = "Contract for $fullname expires in $daysleft days";
$body = " Account expiring in $daysleft days";
sendemail($wordwrap=50, $html=true, $email, $manageremail, '', '', $subject, $body);
}
if ($daysleft == 1) {
//do this for 1 day left before contract ends
$subject = "Contract for $fullname expires in $daysleft days *FINAL NOTICE*";
$body = "Account expiring in $daysleft days";
sendemail($wordwrap=50, $html=true, $email, $manageremail, '', '', $subject, $body);
}
if ($todaydate >= $contractend_TS) {
//do this for expired accounts.... :
$subject = "Contract for $fullname has expired";
$body = "Contract for $fullname has expired";
sendemail($wordwrap=50, $html=true, $email, $manageremail, '', '', $subject, $body);
}
我正在使用PHPMailer ...我會看看我能做些什麼。感謝您的幫助 – rubberchicken
我錯過了$ mail = new PHPMailer();在sendemail函數中...謝謝哥們:) – rubberchicken