gpt4 book ai didi

php - 使用 PHP Mailer 时获取 "Cannot access empty property"

转载 作者:行者123 更新时间:2023-12-02 12:04:25 35 4
gpt4 key购买 nike

我在尝试使用 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 = "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';


?>

编辑

根据其中一个答案中的建议,我尝试使用 $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

最佳答案

尝试编写$this->编码

访问成员变量不需要额外的 $ 符号。

此外,我在这里向您展示我的旧框架中的邮件类。

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

关于php - 使用 PHP Mailer 时获取 "Cannot access empty property",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5359780/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com