簡體   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