简体   繁体   English

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

[英]What is wrong with this PHP script to send mail using Pear Mail?

I have this script: 我有这个脚本:

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

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. Pear Mail安装在服务器上。

Non-static method Mail::factory() should not be called statically 不应静态调用非静态方法Mail :: factory()

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

After reviewing the documentation , your call to Mail::factory looks completely correct and normal. 查看文档后 ,您对Mail::factory调用看起来完全正确且正常。

You failed to tell us if if the call to send succeeds or fails. 您没有告诉我们send的调用是成功还是失败。 If it's succeeding, but the mail is never being delivered, please check the SMTP server logs. 如果它成功,但邮件永远不会被传递,请检查SMTP服务器日志。 If it's failing, what's the actual error message? 如果它失败了,那么实际的错误信息是什么? The Mail::send documentation includes a comprehensive list of errors. Mail::send文档包含一个完整的错误列表。

You might want to consider using a more modern mail sending library, like Swiftmailer . 您可能需要考虑使用更现代的邮件发送库,例如Swiftmailer

prepended an @ to all pear / mail calls. 在所有梨/邮件电话上添加@。 sometime you may end up with Mail::factory() should not be called statically error 有时你可能最终得到Mail :: factory()不应该被称为静态错误

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 =& 请注意使用=&的分配

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM