PHP:PEAR邮件帮助

iam*_*esy 33 php email pear

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

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!
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

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

}
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

Ari*_*osh 31

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

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


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

function &factory($driver, $params = array())
Run Code Online (Sandbox Code Playgroud)

static function &factory($driver, $params = array())
Run Code Online (Sandbox Code Playgroud)

同样在php/pear/Mail.php转到第253行并更改:

$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);
Run Code Online (Sandbox Code Playgroud)

$Mail_RFC822 = new Mail_RFC822();
$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);
Run Code Online (Sandbox Code Playgroud)

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

function isError($data, $code = null)
Run Code Online (Sandbox Code Playgroud)

static function isError($data, $code = null)
Run Code Online (Sandbox Code Playgroud)

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

  • 确认这适用于php 5.5. (4认同)
  • @ekerner有趣的是你应该说......问题的根源是梨.他们将他们的存储库移动到github,并放弃了那里的网站库.梨的更新版本正是这些变化,一行一行.因此,如果你最终更新梨,这些变化将坚持下去.对于某些人来说,比更新整个旧系统更容易进行几行编辑.对于压缩机和其他能够做得更好的机器人而言,已经放弃了梨. (4认同)

cwe*_*ske 11

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

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

  • 这就像说"关闭电脑,然后你永远不会看到任何类型的错误!"一样好. (7认同)
  • 我觉得应该有一个比这更好的答案,Mail包是否应该引发这些错误?简单地称它为非静态不是更好吗? (3认同)

小智 8

@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>");  }
Run Code Online (Sandbox Code Playgroud)

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


AL *_*e X 5

作为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!