I have this script:
require_once "Mail.php";
$from = "Stephen <username@nvrforget.com>";//Google apps domain
$to = "username@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "mail.nvrforget.com";
$username = "username@nvrforget.com";
$password = "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 coming up with this error:
Non-static method Mail::factory() should not be called statically
Any idea how to fix this? Pear Mail is installed on the server.
This is a non-fatal notice coming from PHP because PEAR Mail is prehistoric and hasn’t been updated to use the
statickeyword introduced five years ago in PHP5.After reviewing the documentation, your call to
Mail::factorylooks completely correct and normal.You failed to tell us if if the call to
sendsucceeds or fails. If it’s succeeding, but the mail is never being delivered, please check the SMTP server logs. If it’s failing, what’s the actual error message? TheMail::senddocumentation includes a comprehensive list of errors.You might want to consider using a more modern mail sending library, like Swiftmailer.