PHP: PEAR mail help PHP: PEAR mail help php php

PHP: PEAR mail help


I asked the same question over here, and found a real solution (instead of masking errors). Read the answer to the question below for more details, but basically just follow the three edits below.

How to not call a function statically in php?


Find php/pear/Mail.php, go to line 74 and change:

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

to

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

Also in php/pear/Mail.php go to line 253 and change:

$addresses = Mail_RFC822::parseAddressList($recipients, 'localhost', false);

to

$Mail_RFC822 = new Mail_RFC822();$addresses = $Mail_RFC822->parseAddressList($recipients, 'localhost', false);

Find php/pear/PEAR.php, go to line 250 and change:

function isError($data, $code = null)

to

static function isError($data, $code = null)

Thanks for Amal for showing how to fix this!


The strict errors do not prevent the code from working.

Just set the error reporting setting to E_ALL & ~E_STRICT and they will magically disappear.


@require_once "Mail.php";$headers = array ('From' => $from,'To' => $to,'Subject' => $subject);$smtp = @Mail::factory('smtp', array ('host' => $host,'port' => $port,'auth' => true,        'username' => $UName,'password' => $UPass));$mail = @$smtp->send($to, $headers, $body);if (@PEAR::isError($mail)){   echo("<p>".$mail->getMessage()."</p>"); }else{   echo("<p>Message successfully sent!</p>");  }

Look: I used the @ sign before some of the variables and methods. And with this way you can send email using php5. This is an old aproach, but should work. Though you might be asked about enabling ssl in configuration but that's a piece of cake. Enjoy. And, of course alernate but latest and great technique is using SwiftMailer .