2016-07-22 97 views
0

我有這樣的錯誤,而試圖改善的PHPMailer在我的網站發送自動電子郵件:致命錯誤:調用一個成員函數授權()一個非對象

Fatal error: Call to a member function authorise() on a non-object in /home/u289995868/public_html/es/php/class.user.php on line 116


的「在文件損壞」的代碼是這樣的:

function send_mail($email,$message,$subject) 
    {  
     require_once 'mailer/class.phpmailer.php'; 
     require_once 'mailer/class.pop3.php'; 
     $pop->authorise('mx1.hostinger.es', 110, 30, '[email protected]', 'xxxxxxxx', 1); 
     $mail = new PHPMailer(); 
     $mail->SMTPDebug = 2; 
     $mail->isSMTP(); 
     $mail->isHTML(false); 
     $mail->Host = 'mx1.hostinger.es'; 
     $mail->From = '[email protected]'; 
     $mail->FromName = 'Admin de barreeeiroo.ga'; 
     $mail->Subject = $subject; 
     $mail->Body = $message; 
     $mail->addAddress($email); 
     if (!$mail->send()) { 
      echo $mail->ErrorInfo; 
     } 
    } 


損壞的行是$pop->authorise(...);

你可以看看這裏的require_once文件:GitHub


感謝您的回答。

+0

有你的函數的能見度範圍內沒有對象$流行 –

+0

你也許應該補充所需文件的代碼,因此,答案總是會適應的原因。如果你不這樣做,沒有人會在更新後理解這個問題。 – Unex

+0

像Unex說的 - 如果你已經在你的Github問題中發佈你的代碼,你可能會得到一個答案。 – Synchro

回答

0

$ pop不能在popBeforeSmtp()方法之外使用。嘗試:

require_once 'mailer/class.phpmailer.php'; 
require_once 'mailer/class.pop3.php'; 
$pop = new POP3; 
$pop->authorise('mx1.hostinger.es', 110, 30, '[email protected]', 'xxxxxxxx', 1); 
$mail = new PHPMailer(); 
$mail->SMTPDebug = 2; 
$mail->isSMTP(); 
$mail->isHTML(false); 
$mail->Host = 'mx1.hostinger.es'; 
$mail->From = '[email protected]'; 
$mail->FromName = 'Admin de barreeeiroo.ga'; 
$mail->Subject = $subject; 
$mail->Body = $message; 
$mail->addAddress($email); 
if (!$mail->send()) { 
    echo $mail->ErrorInfo; 
} 
+0

謝謝,它的工作 –

+0

更簡單的使用'POP3 :: popBeforeSmtp()'靜態包裝。此代碼不適用於最新版本的PHPMailer,因爲它缺少自動加載器,因此將無法使用SMTP。 – Synchro

0

變量$pop沒有在你的函數中初始化,所以你實際上在做的是null->authorise(...);,這是沒有意義的。