这个使用 Pear Mail 发送邮件的 PHP 脚本有什么问题? [英] What is wrong with this PHP script to send mail using Pear Mail?

查看:20
本文介绍了这个使用 Pear Mail 发送邮件的 PHP 脚本有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本:

require_once "Mail.php";

 $from = "Stephen <username@nvrforget.com>";//Google apps domain
 $to = "username@gmail.com";
 $subject = "Hi!";
 $body = "Hi,

How are you?";

 $host = "mail.nvrforget.com";
 $username = "username@nvrforget.com";
 $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 已安装在服务器上.

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

推荐答案

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

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

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

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.

查看文档后,您对Mail的调用::factory 看起来完全正确和正常.

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

您没有告诉我们对 send 的调用是成功还是失败.如果成功了,但邮件始终没有送达,请检查 SMTP 服务器日志.如果失败,实际的错误信息是什么?Mail::send 文档包括一个全面的错误列表.

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.

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

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

这篇关于这个使用 Pear Mail 发送邮件的 PHP 脚本有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆