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!
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: