blogo blogo - 14 days ago 5
PHP Question

PHP PEAR Mail Fatal Error

I am trying to send transactional emails with PEAR. My PHP code:

include('Mail.php');
include('Mail/mime.php');

$text = 'test text';
$html = '<html><body><b>HTML</b></body></html>';
$crlf = "\n";
$hdrs = array(
'From' => '***@***.com',
'Subject' => 'Test - PEAR mail'
);

$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail = Mail::factory('smtp',
array ('host' => 'mail.***.com',
'auth' => true,
'username' => '***@***.com',
'password' => '***'));

$mail->send(***@***.com, $hdrs, $body);


The result:

"Fatal error: Call to undefined method PEAR::raiseError() in /home4/good7/php/Net/SMTP.php on line 349"

I had a look at line 349 in SMTP.php:

return PEAR::raiseError('Invalid response code received from server', $this->code);


I am assuming that the error is in my code, not in SMTP.php, but I can't find it.

This site is on shared hosting.

Any insight appreciated.

Dez Dez
Answer

It looks like you don't have the needed PEAR module available. Being on a shared host, first check you have PEAR rightly installed following their own tutorial: https://pear.php.net/manual/en/installation.checking.php

And after that, if it is not installed rightly, follow the shared host tutorial, taking in count you might be limited by your hosting provider in of the actions you need to accomplish: https://pear.php.net/manual/en/installation.shared.php

Comments