2011-03-19 88 views
2

我收到嘗試使用PHP Mailer的錯誤消息。請讓我知道,如果你看到什麼是錯的。使用PHP Mailer時出現「無法訪問空屬性」

Fatal error: Cannot access empty property in /hsphere/local/home/c263430/quoralist.com/includes/phpmailer/phpmailer.inc.php on line 271 

phpmailer.inc.php的271行是

$header[] = sprintf("Content-Transfer-Encoding: %s\n", $this->$Encoding); 

調用phpmailer.inc.php的代碼是

<?php 

require_once("../includes/phpmailer/phpmailer.inc.php"); 
require_once("../includes/phpmailer/smtp.inc.php"); 
$to_name = "Junk Mail"; 
$to = "[email protected]"; 
$subject = "Mail Test at ".strftime("%T", time()); 
$message = "This is a test."; 
$message = wordwrap($message, 70); 
$from_name = "Michael Mitchell"; 
$from = "[email protected]"; 

//Php mail version (default) 
$mail = new PHPMailer(); 

//$mail->IsSMTP(); 
//$mail->Host = "host" 
//$mail->Port  = 25; 
//$mail->SMTPAuth = false; 
//$mail->Username = "username"; 
//$mail->Password = "password"; 


$mail->FromName = $from_name; 
$mail->From  = $from; 
$mail->AddAddress($to, $to_name); 
$mail->Subject = $subject; 
$mail->Body  = $message; 

$result = $mail->Send(); 

echo $result ? 'Sent' : 'Error'; 


?> 

EDIT

以下在一個建議的答案,我試過$this->Encoding而不是$this->$Encoding。當我運行它時,我收到了一條新的錯誤消息,不確定它是否相關。

Fatal error: Cannot redeclare class SMTP in /hsphere/local/home/c263430/quoralist.com/includes/phpmailer/smtp.inc.php on line 26 

的類別在smtp.inc.php的第26行是

class SMTP { 
     var $SMTP_PORT = 25; # the default SMTP PORT 
     var $CRLF = "\r\n"; # CRLF pair 

     var $smtp_conn;  # the socket to the server 
     var $error;   # error if any on the last call 
     var $helo_rply;  # the reply the server sent to us for HELO 

     var $do_debug;  # the level of debug to perform 
+0

@邁克爾有你嘗試下載更新的版本PHP梅勒的? – Daniel 2011-03-19 03:07:03

+0

我今天下載了它。這是他們的php5/6下載。你知道我應該下載的另一個版本嗎? – Leahcim 2011-03-19 03:10:30

+0

@Michael由於某種原因,郵件的編碼沒有設置 – Daniel 2011-03-19 03:12:06

回答

3

的問題是這一行:

$header[] = sprintf("Content-Transfer-Encoding: %s\n", $this->$Encoding); 

它改成這樣:

$header[] = sprintf("Content-Transfer-Encoding: %s\n", $this->Encoding); 
4

嘗試寫$這個 - >編碼

訪問成員變量不需要額外的$符號。

另外我在這裏給你展示我的舊框架中的郵件類。

class Utils_EMail { 
    public static function sendMail($subject,$msg,$to = ADMIN_EMAIL_ADRESS){ 
     $headers = "Mime-Version: 1.0 \n"; 
     $headers .= "Content-Type: text/plain;charset=UTF-8 \n"; 
     $headers .= "From: ".mb_encode_mimeheader(HTTP_HOST,"UTF-8","AUTO")."<".SYSTEM_EMAIL_ADRESS."> \n"; 
     $subject = mb_convert_encoding($subject,"UTF-8","AUTO"); 
     $msg = mb_convert_encoding($msg,"UTF-8","AUTO"); 
     mb_internal_encoding("UTF-8"); 
     mb_send_mail($to,$subject,$msg,$headers); 
    } 
} 
+0

取決於變量是如何聲明的 – Daniel 2011-03-19 03:08:14

+0

我試過了,但後來得到了一個不同的錯誤信息,不知道它是否相關。我會用信息更新OP。 – Leahcim 2011-03-19 03:11:07

+0

此外,如果我現在重寫這個,我會使用''而不是「」,因爲當不需要像\ n那樣的換行符時,會帶來更多的性能。因爲換行符需要「」引號。 – 2011-03-19 03:11:15