使用 Pear Mail 发送邮件的 PHP 脚本有什么问题?

发布于 2024-11-30 08:09:46 字数 1290 浏览 1 评论 0原文

我有这个脚本:

require_once "Mail.php";

 $from = "Stephen <[email protected]>";//Google apps domain
 $to = "[email protected]";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";

 $host = "mail.nvrforget.com";
 $username = "[email protected]";
 $password = "password";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }

我遇到了这个错误:

Non-static method Mail::factory() should not be called statically 

知道如何解决这个问题吗? Pear Mail 安装在服务器上。

I have this script:

require_once "Mail.php";

 $from = "Stephen <[email protected]>";//Google apps domain
 $to = "[email protected]";
 $subject = "Hi!";
 $body = "Hi,\n\nHow are you?";

 $host = "mail.nvrforget.com";
 $username = "[email protected]";
 $password = "password";

 $headers = array ('From' => $from,
   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));

 $mail = $smtp->send($to, $headers, $body);

 if (PEAR::isError($mail)) {
   echo("<p>" . $mail->getMessage() . "</p>");
  } else {
   echo("<p>Message successfully sent!</p>");
  }

I am coming up with this error:

Non-static method Mail::factory() should not be called statically 

Any idea how to fix this? Pear Mail is installed on the server.

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

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

发布评论

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

评论(3

锦爱 2024-12-07 08:09:46

非静态方法 Mail::factory() 不应静态调用

这是来自 PHP 的非致命通知,因为 PEAR Mail 是史前并且尚未更新使用五年前在 PHP5 中引入的 static 关键字。

查看文档之后,您调用 Mail::factory< /code> 看起来完全正确且正常。

您未能告诉我们对 send 的调用是成功还是失败。如果成功,但邮件从未送达,请检查 SMTP 服务器日志。如果失败,实际的错误消息是什么? Mail::send 文档包含全面的错误列表。

您可能需要考虑使用更现代的邮件发送库,例如Swiftmailer

Non-static method Mail::factory() should not be called statically

This is a non-fatal notice coming from PHP because PEAR Mail is prehistoric and hasn't been updated to use the static keyword introduced five years ago in PHP5.

After reviewing the documentation, your call to Mail::factory looks completely correct and normal.

You failed to tell us if if the call to send succeeds or fails. If it's succeeding, but the mail is never being delivered, please check the SMTP server logs. If it's failing, what's the actual error message? The Mail::send documentation includes a comprehensive list of errors.

You might want to consider using a more modern mail sending library, like Swiftmailer.

固执像三岁 2024-12-07 08:09:46

也许这与缺少&符号有关?

我注意到在文档示例中,工厂的用法如下所示:

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);

注意使用 =& 的分配;

perhaps it has to do with a missing ampersand?

I notice in documentation examples, the usage of factory looks like this:

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);

Note the assigment using =&

我是男神闪亮亮 2024-12-07 08:09:46

在所有梨/邮件调用前面添加@。有时你可能会遇到 Mail::factory() Should not be Called statically 错误

prepended an @ to all pear / mail calls. sometime you may end up with Mail::factory() should not be called statically error

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