1
votes

I am trying to send data from a form to an email. I did the following:

  1. Browsed to : http://pear.php.net/package/Mail/download/1.2.0b5
  2. Downloaded the beta file 1.2.0b5
  3. Unziped the file and placed in XAMPP htdocs folder
  4. Created the following code:
<?php // Pear Mail Library

require_once "Mail.php";
$from = '<johannes.gmail.com>';
$to = '<[email protected]>';
$subject = 'Hi!';
$body = "Hi,\n\nHow are you?";

$headers = array(
    'From' => $from,
    'To' => $to,
    'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
        'host' => 'smtp.gmail.com',
        'port' => '465',
        'auth' => true,
        'username' => '[email protected]',
        'password' => 'bon3dfredds'
    ));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
    echo('<p>' . $mail->getMessage() . '</p>');
} else {
    echo('<p>Message successfully sent!</p>');
}

?>

but I get the following error:

Strict Standards: Non-static method Mail::factory() should not be called statically in C:\xampp\htdocs\Mail Tester\Untitled-1.php on line 22

Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in C:\xampp\htdocs\Mail Tester\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 339

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 344 Any help will be greatly appreciated

3

3 Answers

2
votes

I had this same exact problem, but i don't think it's an actual problem. My code executed just fine. it shouldn't be a problem at all and the errors can be supressed. The real problem seems to be that the pear Mail module was written for PHP4 and hasn't been updated since 2010. You can see the discussion via the official bug report against the Mail module. If you would like to, you can update to the the PHP5 friendly Mail2 module that was created to specifically address this problem.

Furthermore, in my code i had to specify the protocol for the server URL.

'host' => 'smtp.gmail.com'

should become

'host' => 'ssl://smtp.gmail.com'

That was the only way I got it to work.

0
votes

The value for $host should just be "smtp.gmail.com".

-1
votes

http://pear.php.net/bugs/bug.php?id=19491

use link above ,its seems work for me..

Just add static keyword in front of function isError

in file PEAR.php