mickyginger — 2012-03-30T09:58:28-04:00 — #1
I need to send an email using PHP. I started using the built in mail function, but I discovered I need SMTP authentication, so I decided to use the PEAR Mail::factory class.
I get a lot of Strict Standards errors, but the email sends. Other forums on the web suggest changing the error_reporting setting in php.ini to E_ALL ^ E_STRICT, to remove the errors. I have done that, but the errors remain. (Besides I'm not overly happy about "hiding" errors. Presumably they are there for a reason.)
Here's the script:
/* mail setup recipients, subject etc */
$recipients = "email@example.com";
$headers["From"] = "firstname.lastname@example.org";
$headers["To"] = "email@example.com";
$headers["Subject"] = "Test";
$mailmsg = "Hello, This is a test.";
/* SMTP server name, port, user/passwd */
$smtpinfo["host"] = "smtp.example.com";
$smtpinfo["port"] = "25";
$smtpinfo["auth"] = true;
$smtpinfo["username"] = "username";
$smtpinfo["password"] = "password";
/* Create the mail object using the Mail::factory method */
$mail_object = Mail::factory("smtp", $smtpinfo);
/* Ok send mail */
$mail_object->send($recipients, $headers, $mailmsg);
The first error message I get is:
Strict Standards: Non-static method Mail::factory() should not be called statically in ... on line ...
most of them refer to methods being called statically. I have no idea what that means, except the opposite of dynamically...
Any help is greatly appreciated,
serverstorm — 2012-03-30T12:13:02-04:00 — #2
The errors are there for a reason and the approach should be solving them rather than suppressing them.
You are calling the factory method statically but that is what the documentation says you should do, so it does not seem to be your code causing this problem. Do you have other objects instantiated prior the the $mail_object? Have you done anything weird with your PHP configuration through PHP.ini?
Did you look at the SwiftMailer library? Great documentation and very solid code and standards compliance. Maybe try and see if you experience similar problems using this library?
mickyginger — 2012-03-30T13:20:43-04:00 — #3
Hi ServerStorm, thanks for your reply.
You are calling the factory method statically but that is what the documentation says you should do, so it does not seem to be your code causing this problem. Do you have other objects instantiated prior the the $mail_object?
Nope, this is the only instance of this object.
Have you done anything weird with your PHP configuration through PHP.ini?
Nothing that I'm aware of. The only changes I've made to php.ini is increased upload_max_filesize and post_max_size, and changed the error_reporting to E_STRICT
I shall take a look at the SwiftMailer library and see if I have any joy.
Thanks for the advice,