Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can one make PHP ignore static method errors when using PEAR Mail extension?

I am using the PEAR Mail extension for PHP 5. I am having difficulties sending mail because it returns this error: Non-static method Mail::factory() should not be called statically.

This is my code:

$from = "Stephen <[email protected]>";
     $to = "helper <[email protected]>";
     $subject = "Email Test!";
     $body = "email test body";

     $host = "smtp.nvrforget.com";
     $username = "[email protected]";
     $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 not receiving the email.

I would use Swiftmailer if I could, but my webhost does not let me.

like image 949
chromedude Avatar asked Nov 27 '25 09:11

chromedude


1 Answers

As PEAR still maintains PHP4 support, you can either...

  1. Create a mail object to use, eg

    $mail = new Mail;
    $smtp = $mail->factory(...
    

    or

  2. Disable E_STRICT errors

    error_reporting(E_ALL ^ E_STRICT);
    

If you insist on using PEAR, the latter may be preferable due to internal static calls to other non-static methods.

like image 53
Phil Avatar answered Nov 28 '25 23:11

Phil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!