2011-03-19 33 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