繁体   English   中英

PHP:PEAR邮件帮助

[英]PHP: PEAR mail help

我正在尝试邮寄梨包。 它成功发送了一封电子邮件但是给我以下错误:

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!

这是我的代码:

function submitTicket(){

     $from = "Billy Jones <billy.jones@networkroi.co.uk>";
     $to = "helpdesk <helpdesk@networkroi.co.uk>";
     $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>");
      }

}

有人可以帮助我吗?

我在这里问了同样的问题,并找到了一个真正的解决方案(而不是掩盖错误)。 请阅读以下问题的答案以获取更多详细信息,但基本上只需按照以下三个编辑进行操作即可。

如何在php中静态调用函数?


找到php/pear/Mail.php ,转到第74行并更改:

function &factory($driver, $params = array())

static function &factory($driver, $params = array())

另外在php/pear/Mail.php转到第253行并更改:

$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);

$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);

找到php/pear/PEAR.php ,转到第250行并更改:

function isError($data, $code = null)

static function isError($data, $code = null)

感谢Amal展示如何解决这个问题!

严格的错误不会阻止代码工作。

只需将错误报告设置设置为E_ALL & ~E_STRICT ,它们就会神奇地消失。

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

看:我在一些变量和方法之前使用了@符号。 通过这种方式,您可以使用php5发送电子邮件。 这是一个古老的方法,但应该有效。 虽然你可能会被问到在配置中启用ssl但这是件小事。 请享用。 而且,当然alernate但最新和伟大的技术是使用SwiftMailer

作为PHP 5的,调用另一个类的非静态方法从禁止的下另一类 IST的非静态方法中E_STRICT PEAR_Mail包被创作时,这在PHP中是一个有点模糊的元编程黑客。 因此, PEAR_Mail因此而臭名昭着。

方法PEAR::isError()可能应该是一个静态方法,但它并不是假设一个实例上下文,其中抛出了大量的$this PEAR_Mail在它自己的实例上下文中静态调用它,因此PHP推断出$this的值...这是各种坏消息。

PEAR_Mail::factory() 定义为static但不是出于原始作者所知的原因。 在修补代码之前,它总是会生成“非静态方法”警告消息。

注意: PEAR_Mail自2010年以来一直未被触及。请不要使用它......! 对于其他选择,请使用Google,Luke!

暂无
暂无

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

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