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

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

问题描述

我有这个脚本:

require_once "Mail.php";

 $from = "Stephen <username@nvrforget.com>";//Google apps domain
 $to = "username@gmail.com";
 $subject = "Hi!";
 $body = "Hi,\n\nHow 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 

任何想法如何解决这个问题?邮件安装在服务器上。

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 Mail是史前,并没有被更新为使用五年前在PHP5中引入的 static 关键字。

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.

你没有告诉我们, 发送成功或失败。如果成功,但邮件从未交付,请检查SMTP服务器日志。如果失败,实际的错误信息是什么? c $ c < a>文档包括一个完整的错误列表。

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.

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

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