PHP、PHPMailer:无法获取 PHPMailer 工作的示例代码

发布于 2024-10-11 11:53:16 字数 1604 浏览 3 评论 0原文

我正在尝试让 php 邮件程序正常工作。我收到错误,但无法从谷歌找到任何相关信息。

$mail = new phpmailer;

$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;

$mail->From = "[email protected]";
$mail->FromName = "Mailer";
$mail->AddAddress("[email protected]", "User");
//$mail->AddAddress("[email protected]");   // name is optional
$mail->AddReplyTo("[email protected]", "Information");
$mail->WordWrap = 50;    // set word wrap
//$mail->AddAttachment("c:\\temp\\js-bak.sql");  // add attachments
//$mail->AddAttachment("c:/temp/11-10-00.zip");

$mail->IsHTML(true);    // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->Send(); // send message

上面的代码是我正在使用的,但是当我尝试运行它时,我在浏览器中看到以下内容...

Fatal error: Cannot access empty property in /the/full/path/to/phpmailer.inc.php on line 271

这是它所指的行...

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

如果有人可以提供帮助,我们将不胜感激!谢谢。

I'm trying to get php mailer to work. I'm getting an error but couldn't find any info from google on it.

$mail = new phpmailer;

$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;

$mail->From = "[email protected]";
$mail->FromName = "Mailer";
$mail->AddAddress("[email protected]", "User");
//$mail->AddAddress("[email protected]");   // name is optional
$mail->AddReplyTo("[email protected]", "Information");
$mail->WordWrap = 50;    // set word wrap
//$mail->AddAttachment("c:\\temp\\js-bak.sql");  // add attachments
//$mail->AddAttachment("c:/temp/11-10-00.zip");

$mail->IsHTML(true);    // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->Send(); // send message

The code above is what I'm using but when I try to run it I get the following in my browser...

Fatal error: Cannot access empty property in /the/full/path/to/phpmailer.inc.php on line 271

Here is the line it's referring to...

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

If anyone can help it would be greatly appreciated! Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

泪是无色的血 2024-10-18 11:53:16

Encoding 不是变量:$this->Encoding

Encoding is not a variable: $this->Encoding

记忆里有你的影子 2024-10-18 11:53:16

文件 phpmailer.inc.php 中的第 271 行有错误

该行是:

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

将其更改为:

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

There's an error on line 271 in file phpmailer.inc.php

The line is :

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

Change it for :

$header[] = sprintf("Content-Transfer-Encoding: %s\n", $this->Encoding);
☆獨立☆ 2024-10-18 11:53:16

您确定要 $this->$Encoding 吗?我认为你想要 $this->Encoding (注意 Encoding 上缺少 $)。

Are you sure you want $this->$Encoding? I think you want $this->Encoding (note the lack of $ on Encoding).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文