PEAR, SMTP and PHP errors

SupermanInNY

Verified User
Joined
Sep 28, 2004
Messages
419
[RESOLVED! - see below]

Hi All,

I tried to use PEAR with Mail.php to enforce better outgoing email management.
PEAR seems simple enough to use, stick a 'require_once' statement and then provide the handshake info (server, account name and password) along with the header, body strings/arrays.

However,. I'm getting errors running the scripts and I don't how to overcome it. I'm stuck on safe_mode limitations or on undeclared functions:

Fatal error: Call to undefined function: send()

<?php
require_once "Mail.php";

$from = "Sandra Sender <[email protected]>";
$to = "Ramona Recipient <[email protected]>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.DDDDD.com";
$username = "[email protected]";
$password = "DDDDDD";

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


This is the line it fails on:
$mail = $smtp->send($to, $headers, $body);


send() is part of the PEAR thingy, but I can't get it to work!

Any pointers?

Yes, I installed PEAR (to the best of my knowledge), but please shed some light on how to check that the install is correct?

Thanks,

-Alon



---------------------------------------------------------------
RESOLVED - HOW TO:
---------------------------------------------------------------

Step 1:

Make sure that your PHP compile has pear included in it:

--with-pear \

Step 2:

Get to know what you need and already have in pear

at the commandline type:

pear list

this will display to you what extentions/packages you already have installed with pear.

This is what I have on my server

Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.2 stable
Console_Getopt 1.2.2 stable
HTML_Template_IT 1.2.1 stable
Mail 1.1.14 stable
Mail_Mime 1.4.0 stable
Net_SMTP 1.2.10 stable
Net_Socket 1.0.8 stable
Net_UserAgent_Detect 2.3.0 stable
PEAR 1.5.4 stable
Structures_Graph 1.0.2 stable

And it worked, so you might want to have a similar settings.

Step 3:

OK.. chances are that you might not have all that I have. So,. install it.
(how???)
Luckily it is not complicated :))

We need to make a small deviation from the straight install.

run the following:
updatedb
locate php.ini

vi /nano /pico php.ini

put a ; (semi-colon) at the begining of the disable_functions so that it will be commented out.

service httpd restart

NOW lets continue with the PEAR installation:


pear install mail

Will install the Mail package.
I don't know why I'm having problems with the connection to the mirror sites, so instead, you can download the tgz files and install them the same way.
For instance:

wget -c http://download.pear.php.net/package/PEAR-1.5.4.tgz

Will get you the file to your server.

Then run:

pear install PEAR-1.5.4.tgz

that's it. It is the same as typing the

pear install pear

Notice that as I'm writting this How-To, there is a msg on Pear's website that 1.6.0 is due out in 5 days.

BUT HEY... I GOT AN ERROR TYPING:

pear install PEAR-1.5.4.tgz

OK.. it is very likely that you already have some parts of PEAR installed (by default),.so you can't install the same package.
But you can UPGRADE it.

pear upgrade PEAR-1.5.4.tgz

Very simple and it runs in two seconds.

Next package that you need to install is:

pear install Net_SMTP

Other package might also be needed,. but you have the list of packages that I have installed on my server and it is working for me.

Step 4:
Are we done yet?

Nope.. almost.

Remember in the previous step, you commented out the disable_functions, you need to UNcomment them so you are back to the security level you were before.

BUT DON'T EXIT THE php.ini yet:

You need to add one more thing:

You have a section that has:

safe_mode_include_dir =

and it is likely to be empty.

Populate it with:

safe_mode_include_dir = /usr/local/lib/php/

NOW save and exit php.ini

service httpd restart

DONE!
 
Last edited:
I tried to follow this how-to but from the beginning i keep getting a message that the pear command cannot be found. What am i overlooking?

[root@s02 ~]# pear
-bash: pear: command not found
 
Thanx for your swift reply Alon. But this is what i get:

[root@s02 ~]# wget -c http://download.pear.php.net/package/PEAR-1.6.1.tgz
--15:42:50-- http://download.pear.php.net/package/PEAR-1.6.1.tgz
=> `PEAR-1.6.1.tgz'
Resolving download.pear.php.net... 216.92.131.66
Connecting to download.pear.php.net|216.92.131.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 295,780 (289K) [application/x-tar]

100%[====================================>] 295,780 244.90K/s

15:42:52 (244.05 KB/s) - `PEAR-1.6.1.tgz' saved [295780/295780]

[root@s02 ~]# pear install pear
-bash: pear: command not found
 
Thanx for your swift reply Alon. But this is what i get:

[root@s02 ~]# wget -c http://download.pear.php.net/package/PEAR-1.6.1.tgz
--15:42:50-- http://download.pear.php.net/package/PEAR-1.6.1.tgz
=> `PEAR-1.6.1.tgz'
Resolving download.pear.php.net... 216.92.131.66
Connecting to download.pear.php.net|216.92.131.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 295,780 (289K) [application/x-tar]

100%[====================================>] 295,780 244.90K/s

15:42:52 (244.05 KB/s) - `PEAR-1.6.1.tgz' saved [295780/295780]

[root@s02 ~]# pear install pear
-bash: pear: command not found


If you have a recent installation of PHP, you can relax: The pear base installation is already there, unless you have compiled your PHP with the ./configure flag --without-pear.

what PHP version do you have isntalled?
 
I use PHP version 4.4.4 and indeed, the base installation is allready there. Using the DA-plugin I can see the following packages installed:

Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
HTML_Template_IT 1.1 stable
Net_UserAgent_Detect 2.0.1 stable
PEAR 1.4.9 stable

But I can still not acces the PEAR command from the command line :(
 
Last edited:
I use PHP version 4.4.4 and indeed, the base installation is allready there. Using the DA-plugin I can see the following packages installed:

Archive_Tar 1.3.1 stable
Console_Getopt 1.2 stable
HTML_Template_IT 1.1 stable
Net_UserAgent_Detect 2.0.1 stable
PEAR 1.4.9 stable

But I can still not acces the PEAR command from the command line :(

run the ./build clean
then ./build update
then ./build php y
with no special addition to the configure.php

That may assist you with the process.
 
smtalk rocks

I had several problems (including not starting https) after doing:

run the ./build clean
then ./build update
then ./build php y
with no special addition to the configure.php

Finaly i got in contact with forum user smtalk. This guy was willing to spent almost an hour on helping me out. Yes, he really rocks and deserves all credit!
 
Back
Top