PHP:PEAR 邮件帮助
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4044996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: PEAR mail help
提问by iamjonesy
I'm trying out the mail pear package. It successfully sends an email but give me the following error:
我正在试用邮件梨包。它成功发送了一封电子邮件,但给我以下错误:
Strict Standards: Non-static method Mail::factory() should not be called statically, assuming $this from incompatible context in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ClientPortal\classes\SupportTickets.php on line 356
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Mail\smtp.php on line 365
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 386
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 391
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 398
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 441
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 445
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Mail\smtp.php on line 376
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 526
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 529
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 532
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 441
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 445
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 550
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 694
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 698
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 706
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 1017
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 415
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\PHP\PEAR\Net\SMTP.php on line 230
Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ClientPortal\classes\SupportTickets.php on line 364
Message successfully sent!
Here's my code:
这是我的代码:
function submitTicket(){
$from = "Billy Jones <[email protected]>";
$to = "helpdesk <[email protected]>";
$subject = "Email Test!";
$body = "email test body";
$host = "***";
$username = "***";
$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>");
}
}
Can some one help me out here?
有人可以帮我吗?
回答by Arian Faurtosh
I asked the same question over here, and found a real solution (instead of masking errors). Read the answer to the question below for more details, but basically just follow the three edits below.
我在这里问了同样的问题,并找到了一个真正的解决方案(而不是掩盖错误)。阅读以下问题的答案以获取更多详细信息,但基本上只需遵循以下三个编辑。
How to not call a function statically in php?
Find php/pear/Mail.php
, go to line 74 and change:
查找php/pear/Mail.php
,转到第 74 行并更改:
function &factory($driver, $params = array())
to
到
static function &factory($driver, $params = array())
Also in php/pear/Mail.php
go to line 253 and change:
同样php/pear/Mail.php
转到第 253 行并更改:
$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
to
到
$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);
Find php/pear/PEAR.php
, go to line 250 and change:
查找php/pear/PEAR.php
,转到第 250 行并更改:
function isError($data, $code = null)
to
到
static function isError($data, $code = null)
Thanks for Amal for showing how to fix this!
感谢 Amal 展示如何解决这个问题!
回答by cweiske
The strict errors do not prevent the code from working.
严格错误不会阻止代码工作。
Just set the error reporting setting to E_ALL & ~E_STRICT
and they will magically disappear.
只需将错误报告设置设置为E_ALL & ~E_STRICT
,它们就会神奇地消失。
回答by Abdul Jabbar
@require_once "Mail.php";
$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);
$smtp = @Mail::factory('smtp', array ('host' => $host,'port' => $port,'auth' => true,
'username' => $UName,'password' => $UPass));
$mail = @$smtp->send($to, $headers, $body);
if (@PEAR::isError($mail))
{ echo("<p>".$mail->getMessage()."</p>"); }
else
{ echo("<p>Message successfully sent!</p>"); }
Look: I used the @
sign before some of the variables and methods. And with this way you can send email using php5. This is an old aproach, but should work. Though you might be asked about enabling ssl in configuration but that's a piece of cake. Enjoy. And, of course alernate but latest and great technique is using SwiftMailer .
看:我@
在一些变量和方法之前使用了符号。通过这种方式,您可以使用 php5 发送电子邮件。这是一种古老的方法,但应该有效。尽管您可能会被问到在配置中启用 ssl 的问题,但这很容易。享受。而且,当然另类但最新的和伟大的技术是使用SwiftMailer。
回答by AL the X
As of PHP 5, calling a non-static method of another class from within the non-static method of anotherclass ist verboten under E_STRICT
. When the PEAR_Mail
package was authored, this was a somewhat obscure meta-programming hack in PHP. Thus PEAR_Mail
is notorious for this.
作为PHP 5的,调用另一个类的非静态方法从的非静态方法中的另一个类IST禁止的下E_STRICT
。在PEAR_Mail
编写包时,这是 PHP 中一个有点晦涩的元编程技巧。因此PEAR_Mail
是臭名昭著的。
The method PEAR::isError()
probably shouldhave been a static method, but it's not and assumes an instance context with lots of $this
thrown around. PEAR_Mail
calls it statically within its own instance context, so PHP infers the value of $this
... Which is all kinds of Bad News.
该方法PEAR::isError()
可能应该是一个静态方法,但它不是,并且假设了一个实例上下文,其中包含大量$this
抛出。PEAR_Mail
在它自己的实例上下文中静态地调用它,所以 PHP 推断出$this
...的值,这是各种坏消息。
PEAR_Mail::factory()
shouldbe defined as static
but isn't for reasons known only to the original authors. It will ALWAYSgenerate that "non-static method" warning message until the code is patched.
PEAR_Mail::factory()
应该被定义为static
但不是因为只有原作者知道的原因。在修补代码之前,它始终会生成“非静态方法”警告消息。
Note:PEAR_Mail
hasn't been touched since 2010. Please don't use it...! For alternatives, use the Google, Luke!
注意:PEAR_Mail
自2010年以来未接触过。请不要使用它......!对于替代方案,请使用谷歌,卢克!