sending mail using php and pear on windows

假装没事ソ 提交于 2019-12-01 00:48:45

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.

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!