3
votes

I am trying to send an e-mail using php script but i am getting errors this is my code.i am using xampp netbeans and windows. and i included pear in the php.ini file but still having thies errors any ideas

 require_once "Mail.php";
                            
                            $from = "[email protected]";
                            $to = "'$email'";
                            $subject = "Online book store information";
                            $body = "This is your Id '$userID' click <a href =../index.php > here </a> to change to go to the website "; //todo change URL to make it work when it is online

                            $host = "ssl://smtp.gmail.com";
                            $port = "993";
                            $host = "smtp.gmail.com";
                            $username = "[email protected]";
                            $password = "";

                            $headers = array('From' => $from,
                                'To' => $to,
                                'Subject' => $subject);
                            $smtp = Mail::factory('smtp', array('host' => $host,
                                        'port' => $port,
                                        '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>");
                            }

and this is the errors i am getting :

Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\OnlineBookStore\Store\Register.php on line 85

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Mail\smtp.php on line 365

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Net\SMTP.php on line 450

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\php\PEAR\Net\SMTP.php on line 467

2
Does the first warning go away if you try: $smtp =& Mail::factory(...); Also see the comments on this post about PEAR mail help - drew010
no it still the same list of error and i checked the php.ini and the E_STRICT and it is for all - dori naji
Changing error_reporting to E_ALL ^ E_STRICT should fix the warnings. You could use error_reporting(E_ALL ^ E_STRICT); at the beginning of that script to only change the error reporting for that particular code. It is just that the PEAR mail class is not fully updated for PHP5 OOP. It should be public static function factory() instead of function &factory( as defined in Mail.php - drew010
can you please specifiy exactly what should i change in the php.ini shoud i change this; Eval the expression with current error_reporting(). Set to true if you want or something else - dori naji
In php.ini, you could set error reporting to error_reporting = E_ALL ^ E_STRICT or just leave php.ini as it is and add error_reporting(E_ALL ^ E_STRICT); at the top of Register.php. - drew010

2 Answers

14
votes

I just ran into the same problem and solved it using:

@require_once "Mail.php";
...
$smtp = @Mail::factory('smtp', array('host' => $host,
                                        'port' => $port,
                                        'auth' => true,
                                        'username' => $username,
                                        'password' => $password));
$mail = @$smtp->send($to, $headers, $body);
if (@PEAR::isError($mail)) {

Notice that I prepended an @ to all pear / mail calls.

I prefer this solution to changing the general error message settings as I don't want to see the pear / mail warnings but I do want to see the ones that apply to my own code.

0
votes

Yes jeroens method doesn't show the warning messages, but does it actually solve the problem? apprehending @ just hides the warning associated with it.

To fix the problem in Mail.php modify the following

function &factory($driver, $params = array())

Change it to

static function &factory($driver, $params = array())

Reason for this error is because PEAR Mail has not been updated to PHP5 Standards and still uses PHP4 so gradually as servers become PHP5 Compliant this will become more frequent. Its better to fix rather than hide.

Hope this helps