SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    PEAR Mail throws numerous errors

    Hi there,

    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:
    PHP Code:
    <?php
    include("Mail.php");

    /* mail setup recipients, subject etc */
    $recipients "example@example.com";
    $headers["From"] = "example@somewhere.com";
    $headers["To"] = "example@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,
    Mike

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by mickyginger View Post
    Hi there,

    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:
    PHP Code:
    <?php
    include("Mail.php");
    ...
     
    /* Create the mail object using the Mail::factory method */
    $mail_object Mail::factory("smtp"$smtpinfo);

    .. 
    ?>
    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,
    Mike
    Hi mickyginger,

    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?

    Regards,
    Steve
    ictus==""

  3. #3
    SitePoint Addict
    Join Date
    Oct 2009
    Location
    London, UK
    Posts
    382
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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,
    Mike


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •