Well, after getting caught out recently with PEAR on a client installation, I thought it a good move to write a short tutorial for anyone who needs to install PEAR packages on their WAMP installation.
To start with, for the purposes of this blog, PEAR is a framework for implementing code libraries in PHP. In other words, it prevents you from having to re-invent the wheel – always a nice thing!
The WAMP installation installs PHP, and at the same time installs the basic PEAR framework. There is a directory called PEAR inside whatever folder contains PHP – on my particular installation the structure is php5.2.5\PEAR. Taking a peek inside the PEAR folder will reveal it populated with the basic framework for PEAR. Most of this you can ignore – I’m not going to detail installing this here – that seems to be well covered. I just couldn’t find out how to actually enabvle the damn packages when I started, so I hope this is useful!
Checking Configuration
This is THE place where things can go PEAR-shaped, if you’ll allow the pun. The PEAR folder must be included in the includes path within PHP.INI. Open PHP.INI and find the line that starts with :
include_path =
or, if commented out
; include_path =
You need to add the path to your PEAR folder to the end of this string. For example:
include_path = “.;e:\wamp\bin\php\php5.2.5\includes;e:\wamp\bin\php\php5.2.5\PEAR”
Now – it is CRUCIAL that there are NO spaces after or before the semi-colons that separate paths in this string. If there are, quite simply, PEAR will not work. Simple as that – any incldue path after such a space will NOT be searched by PHP.
Once you have modified the PHP.INI file, save it and restart your WAMP installation.
Installing a package
First of all, identify the package(s) that you want to install. To do this, take a look at http://pear.php.net/packages.php, which lists the available packages for PEAR. Identify the ones you’re interested in – for the same of example, let’s deal with a Mailer package.
Click on the relevant section of the Package list, and you’ll see a list of available Mail packages. Select the one of interest – choose the package ‘Mail’ and click on it. This will then display a page of details about the Mail package – and also the links to download, documentation, etc. Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not. This blog entry will assume you have – I’ll post the alternative instructions elsewhere.
To start with, make a note of the package name – ‘Mail’.
Check the Dependencies
Click on the ‘Download’ tab – you will see an entry someway down the page for ‘Dependencies’. These are PEAR packages that you need to install for your chosen package to work. Make a note of the dependencies – in this case, Net_SMTP. Now click on that dependency, and check it’s dependencies – do this and you will see Net_Socket and Auth_SASL listed. The latter is optional, so I won’t bother with that. There are two other packages listed – however they’re part of the PEAR framework.
So, we now have a list of packages to download and install. These are:
Mail, Net_SMTP, Net_Socket. (We’ll ignore the Auth_SASL one for this example).
Whilst you can automate the acquisition of dependencies, it’s educational to do it ‘the hard way’ at first. 🙂 So that’s what we will do!
Start a Command Window
From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’. Now change directory to the PHP directory. On my machine this is:
E:\wamp\bin\php\php5.2.5
Once in there, type in pear list. This will list the currently installed pear packages. If it’s a new PEAR installation, there will be 3 packages listed 4 packages listed – PEAR, Archie_Tar, Console_Getopt and Structures_graph.
Now, type in pear update-channels. this connects to the PEAR repository – where the PEAR files live – and updates your local installation with data needed to get packages.
Now, type in:
pear download Mail
pear install Mail
The former command gets a ZIP file containing the Mail package from the PEAR repository, and the latter will install the mail package. Note the messages displayed on installation – the software warns you that you haven’t got the dependencies, and gives you a suggestion of a method of downloading the dependencies – which we’ll now use to get Net_SMTP an it’s dependencies.
We’ll also do this installation slightly different to the first one – thus showing there is more than one way to install a package. Type in:
pear install -a Net_SMTP
No download this time – this will go off and get Net_SMTP, and all of it’s dependencies, and install them – all in one fell swoop! The -a switch tells PEAR to get all the dependencies.
The files will be installed in to the PEAR folder. Sometiems a PHP file will be placed in the folder itself – as happens with the DB package. Other times a new folder will be created – like for Mail – and the PHP files placed in the new folder.
Testing the mailer.
Here is a piece of sample code to put in to a PHP file:
<?php
require_once "Mail.php";
$from = "Sender <sender@example.com>";
$to = "Recipient <recipient@example.com>";
$subject = "Hi!";
$body = "Hi,\n\nThis is a test!";
$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";
$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>");
}
?>
Set up your own parameters for the mail server and the authentication required – username and password, and the address of the recipient – and if you have successfully installed PEAR Mail then you should get a mail sent. If you get any messages back refering to ‘No such file or directory’ then the chances are that the configuration of PHP.INI is a little screwed up. And there you have it!
Hi Joe,
Thanks a million for such great tutorial…i have been scraping around my mind for it..and luckily found this one…u are such a gem…
keep it up!
baran
Thank you!
Much appreciated – the nonsense with the space in the include_path kept me scratching my head for some time.
Glad you found it useful!
Hello Joe,
“From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’. Now change directory to the PHP directory. On my machine this is:
E:\wamp\bin\php\php5.2.5
Once in there, type in pear list.
”
When I type pear list, and I sure am in the right directory, I don’t see anything in the cmd window.
“Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not. This blog entry will assume you have – I’ll post the alternative instructions elsewhere.”
Can I find the alternative instructions yet on your website?
By thanking you in advance,
BKS
Oh !!!
Really thanks for this tutorial, it’s very usefull !
Good job man.
SnoT.
Sadly the version of wamp I currently have only has a go-pear.bat and seemingly not a pear.bat type file.
Command line options don’t seem to function for the go-pear command. I’m just about to download the latest version of wamp to see what’s going on.
I noticed a pear-old.bat file which might suggest that pear.bat is no longer the way wamp does Pear installations? Any ideas?
Thanks,
Mike.
YOU ARE THE MAN!!!
I have spent HOURS getting mail to work with pear,
NONE of the other sites tell you that you have to INSTALL
Mail first … and if they do none of them really tell you HOW
to do it …
I can’t believe that EVERY step you listed worked 100%.
Though I realized that using the shell from UnxUtils will NOT work – it must be cmd.exe
thanks again!!!
WASTED TUTORIAL!
Dont work with pear list, and no instructions gived for the alternative method.
Using newest wamp.
0 points.
Hi Martin,
Well, it worked for me, it’s worked for others, and I’m sorry it didn’t work for you.
Hope you find an answer.
Fantastic Joe, I struggled with this for some time until I found your article and have never looked back from using PEAR.
To take this a step further:
Send Mail Requiring SSL and Authentication
In this case further setup is required:
1. Check that php_openssl.dll exists in the ext folder.
2. check: PHP.ini – extension=php_openssl.dll extension is enabled.
Now the code needs extra arguments to be passed. Let’s assume we want to use a Google mail account:
$host = ‘ssl://smtp.gmail.com’;
$username = ‘user@googlemail.com’;
$password = ‘pw’;
$headers = array (
‘From’ => $from,
‘To’ => $to,
‘Subject’ => $subject
);
$smtp = Mail::factory(
‘smtp’,
array (
‘host’ => $host,
‘IDhost’ => “gmail.com”,
‘port’ => 465,
‘auth’ => true,
‘username’ => $username,
‘password’ => $password
)
);
$mail = $smtp->send($to, $headers, $body);
Thanks again.
Sorry Joe, lost my indentation, please fix during moderation and delete this comment. Should have used pre tags I guess?
Hello Joe.
your post is really nice.
when i try ti install ilias open source with WAMP then pear problem ariease .
thanks
Hi joe,
thaks for the tutorial..it’s really great…i followed all the steps above and installed the mail successfully…i can see the packages when i type pear list…but the problem is none of the examples based on the pear mail are not working for me…they’re always throwing the error Class ‘Mail’ not found …is there anything that i should do..?i’ve changed the include_path variable in php.ini files present in both the php folder and the one in the apache/bin folder…
any help would be realllllly great…
thanks again,
ravi.
sorry for bothering you…dont mind about my previous comment…i renamed my example file to something else from mail.php and it worked perfectly…
also thanks to williabee for instructions on using authentication…
and for others…the other method that was not mentioned in the original post that installs all the dependencies too is this:
just type
pear install –alldeps mail
instead of the pear download mail,pear install mail and then installing the dependencies…
ravi
Pingback: How to install PHP PEAR::Mail Class in WAMP2 at Get RIAed
You rock, this is the best tutorial I’ve read to get the php pear smtp mail function working!
I’d been trying every night for 3 weeks to get this working on my windows box!
However my LAMP server with mail seemed go easier on my GNU/Linux Debian running Gnome box!
I’ll take them both though!
Thanks a million!
(AIG Dollars not mine, arh..well I guess there mine too)
Brett
hi iv had this problem for weeks, although i am new too this its really buging me, please help i keep getting this error
Failed opening required ‘Mail.php’ (include_path=’.;C:\php5\pear’
i have windows vista, wamp, C:\wamp\bin\php\php5.3.0
my include path in my php.configuration Settings ini file is like this ….
;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;
; UNIX: “/path1:/path2”
;include_path = “.:/php/includes”
;
; Windows: “\path1;\path2”
include_path = “.;c:\php\includes;C:\wamp\bin\php\php5.3.0\includes;C:\wamp\bin\php\php5.3.0\PEAR”
;
; PHP’s default setting for include_path is “.;/path/to/php/pear”
; http://php.net/include-path
i installed wamp originally by going
start->run->cmd
cd C:\wamp\bin\php\php5.3.0
then go-pear.bat
then jus pressed yes and enter to all the questions
is there somet iv done wrong…… please help me
Hi Luke,
From what you’ve posted I can’t see anything that’s immediately wrong, BUT it may be worth while checking that the php.ini file that you’ve modified is actually the oine being used by PHP. Run a script with phpinfo() in it to get a list of the settings for PHP and check that the path is what you’ve entered.
If it isn’t, then look for other PHP.INI files in your wamp installation and find teh one being used.
Installing PEAR packages on WAMP post for thanx..
People having trouble running “pear list” should run go-pear.bat first. It will install pear and update php.ini: just accept default values by pressing ENTER. Then run “pear list” and follow the rest of the tutorial.
i really thankful to you for giving me the correct code
Please help me.
At your tutoring in this URL:
http://www.joep.communityhost.org.uk/?p=30
I’m in this step :
Start a Command Window, type in pear list.
I type Pear list and it writte to me:
‘PEAR’ is not known as an intern or extern command, an executable programm or an extern file.
Please help me know what should I do to type Pear List in order to list the currently installed pear packages. And in order to move to the next steps at your tutoring.
Hi, and ty for the post, mine works to some extent.
After I have done the PEAR installation, it shows this path in the php.ini file(right at the bottom)
;***** Added by go-pear
include_path=”.;D:\wamp\bin\php\php5.3.5\PEAR”
;*****
The path is correct, but what you are showing in your post, makes me wonder if I have to cut this and paste it where you are saying it must go.
I can go as far as downloading the packages via CMD, but when I want to install it, it gives me “require_once Structure/…” basically, its says that the it cant get certain files.
I have another question about my paths:
bin/php/php5.3.5/PEAR
then there is this one
bin/php/php5.3.5/PEAR/PEAR
why is there another PEAR folder with more files in? which is the correct folder to specify in my php.ini?
Thanks, please help
i am trying to send mail with this code…i am getting error like this
authentication failure [SMTP: SMTP server does not support authentication (code: 250, response: mx.google.com at your service, [122.167.227.83] SIZE 35882577 8BITMIME STARTTLS ENHANCEDSTATUSCODES)]
i have installed all the packages…nd i am using php version 5.2.6
Please help me in this…..
thanks in advance
I”m getting this error when running a sample file email.php with require_once “Mail.php”;
Warning: require_once(/path/to/pear/Mail.php) [function.require-once]: failed to open stream: No such file or directory in….
phpinfo() shows this
include_path .;c:\php\includes;C:\wamp\bin\php\php5.3.5;E:\New folder\PHP\library;C:\wamp\bin\php\php5.3.10\pear
The error message shows the way….
“authentication failure” means that there is a problem with the way you are trying to use the SMTP server – the extended message shows that the server you’re trying to use doesn’t actually support authentication.
Just check with Google that you’re permitted to use that server for outgoing mail via PHP in this way.
You’ve not set the correct path to where the Mail.php file is.
The /path/to/pear/Mail.php path MUST be replaced with the actual path to the pear folder and file.
Joe
Thanks for the tutorial…however it didn’t completely work for me as I was unable to connect. This is the error
Updating channel “doc.php.net”
Channel “doc.php.net” is not responding over http://, failed with message: Conne
ction to `doc.php.net:80′ failed: A connection attempt failed because the connec
ted party did not properly respond after a period of time, or established connec
tion failed because connected host has failed to respond.
and so on…I tried to fix the above problem with no luck.
So I downloaded the packages manually, extracted the files to a temp folder and then copied them to the php5.3.8\pear folder.
Then I typed the installation commands from the pear folder with the complete package names:
pear install NetSMTP-1.6.1
pear install Net_Socket-1.0.10
pear install Mail-1.2.0
And viola! It worked. Hope that helps someone else.
Tim
Thanks for the feedback – must admit that I’ve not checked the method to see if it’s still valid after this length of time! Things seem to change so quickly online! Many thanks!
Thank so much, man. For today, you are my God. You saved my day because I didn’t have idea about that steps.
Thanks – you’re welcome! These things bug me too!
Where i put this php file (i mean the script that is required for sending mail ) , should i put it within C:\wamp\www or C:\wamp\bin\php\php5.3.3\www
Help me Sir. Thank you
Hi there,
The test script – the bit at the end that sends the mail – should be placed in the wamp\www folder, along with your other website pages.
Thanks,
Joe
Very nice work. 🙂
Don’t forget to enable ‘php_openssl’ if you are sending through ‘ssl’ host.
Thanks.
It’s still doesn’t work with me >_<
Hi,
I’m sorry you’ve had problems with this…however, it was written some years ago and I definitely haven’t tried it with newer versions of PHP…sorry!
Thanks a lot for the help 🙂