Take the 2-minute tour ×

I have this script:

require_once "Mail.php";

 $from = "Stephen <username@nvrforget.com>";//Google apps domain
 $to = "username@gmail.com";
 $subject = "Hi!";

 $host = "mail.nvrforget.com";
 $username = "username@nvrforget.com";
 $password = "password";

   'To' => $to,
   'Subject' => $subject);
 $smtp = Mail::factory('smtp',
   array ('host' => $host,
     'auth' => true,
     'username' => $username,
     'password' => $password));


 if (PEAR::isError($mail)) {
  } else {

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.

share|improve this question
Looks correct. Are you sure your Pear Mail library is being included properly? –  labue Aug 18 '11 at 21:20

3 Answers 3

up vote 9 down vote accepted


This is a non-fatal notice coming from PHP because PEAR Mail is prehistoric and hasn't been updated to use the static keyword introduced five years ago in PHP5.

After reviewing the documentation, your call to Mail::factory looks completely correct and normal.

You failed to tell us if if the call to send succeeds 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? The Mail::send documentation includes a comprehensive list of errors.

You might want to consider using a more modern mail sending library, like Swiftmailer.

share|improve this answer
Ah... very interesting. The send doesn't seem to succeed. I will try out swiftmailer, because I would definitely prefer to have a more modern library. Thanks. –  chromedude Aug 18 '11 at 21:37

perhaps it has to do with a missing ampersand?

I notice in documentation examples, the usage of factory looks like this:

// Create the mail object using the Mail::factory method
$mail_object =& Mail::factory('sendmail', $params);

Note the assigment using =&

share|improve this answer
-1, there is no longer any need to pass objects by reference in PHP5. That syntax is for PHP4 only. –  Charles Aug 18 '11 at 21:32

prepended an @ to all pear / mail calls. sometime you may end up with Mail::factory() should not be called statically error

share|improve this answer

Your Answer


