使用 Pear Mail 发送邮件的 PHP 脚本有什么问题?
我有这个脚本:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是来自 PHP 的非致命通知,因为 PEAR Mail 是史前并且尚未更新使用五年前在 PHP5 中引入的
static
关键字。在查看文档之后,您调用
Mail::factory< /code> 看起来完全正确且正常。
您未能告诉我们对
send
的调用是成功还是失败。如果成功,但邮件从未送达,请检查 SMTP 服务器日志。如果失败,实际的错误消息是什么?Mail::send
文档包含全面的错误列表。您可能需要考虑使用更现代的邮件发送库,例如Swiftmailer。
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? TheMail::send
documentation includes a comprehensive list of errors.You might want to consider using a more modern mail sending library, like Swiftmailer.
也许这与缺少&符号有关?
我注意到在文档示例中,工厂的用法如下所示:
注意使用 =& 的分配;
perhaps it has to do with a missing ampersand?
I notice in documentation examples, the usage of factory looks like this:
Note the assigment using =&
在所有梨/邮件调用前面添加@。有时你可能会遇到 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