开发者

Getting "Cannot access empty property" when using PHP Mailer

开发者 https://www.devze.com 2023-02-17 15:26 出处:网络
I\'m getting this error message trying to use PHP Mailer.Please let me know if you see what is wrong.

I'm getting this error message trying to use PHP Mailer. Please let me know if you see what is wrong.

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

Line 271 of phpmailer.inc.php is

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

The code that called phpmailer.inc.php is

<?php

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

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

following a suggestion in one of the answers, I tried $this->Encoding instead of $this-&开发者_如何学Cgt;$Encoding. When I ran it I got a new error message, not sure if it's related.

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

The class at line 26 of smtp.inc.php is

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


try to write $this->Encoding

accessing member variables does not require an additional $ sign.

In addition I show you here my mail class from my old framework.

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);
    }
}


The problem is this line:

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

Change it to this:

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


I had this exact error. Check what version of PHPMailer you're using. I downloaded Version 5/6 from sourceforge.net and somehow ended up with the original version from 2001.

Get the latest one from here:

http://code.google.com/a/apache-extras.org/p/phpmailer/downloads/list

0

精彩评论

暂无评论...
验证码 换一张
取 消