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

时间:2021-01-08 07:16:52

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邮件安装在服务器上。

3 个解决方案

#1


11  

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

非静态方法邮件::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邮件是史前的,而且还没有更新到使用PHP5中五年前引入的静态关键字。

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. 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.

您没有告诉我们发送的调用是否成功或失败。如果它成功了,但是从来没有发送邮件,请检查SMTP服务器日志。如果失败,实际的错误消息是什么?邮件::发送文档包含一个完整的错误列表。

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

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

#2


-2  

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 =&

请注意使用=&。

#3


-2  

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

在所有的pear / mail电话前加上@。有时您可能会以Mail:::factory()结束,不应该被称为静态错误

#1


11  

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

非静态方法邮件::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邮件是史前的,而且还没有更新到使用PHP5中五年前引入的静态关键字。

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. 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.

您没有告诉我们发送的调用是否成功或失败。如果它成功了,但是从来没有发送邮件,请检查SMTP服务器日志。如果失败,实际的错误消息是什么?邮件::发送文档包含一个完整的错误列表。

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

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

#2


-2  

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 =&

请注意使用=&。

#3


-2  

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

在所有的pear / mail电话前加上@。有时您可能会以Mail:::factory()结束,不应该被称为静态错误