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.
As PEAR still maintains PHP4 support, you can either...
Create a mail object to use, eg
$mail = new Mail;
$smtp = $mail->factory(...
or
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With