Home arrow Blog arrow Installing PEAR::Mail Class in WAMP2
Installing PEAR::Mail Class in WAMP2 PDF Print E-mail
Friday, 21 March 2008

Getting the Mail class from PEAR working in a new WAMP installation can look tricky, but these steps should help.

If you ran the go-pear.bat file and installed PEAR, and then installed the Mail package with all its dependencies, you should now have the required files in your system, especially:

c:\wamp\bin\php\php5.2.5\PEAR\Mail.php


If you cannot find that file but you have PEAR installed, you can just run the following command to install the Mail package:

pear install --alldeps mail

Mail.php is the file where the Mail class and the factory function reside - remember Mail::factory(). You need to add the PEAR folder to the include_path in the php.ini which Apache uses.

Edit this php.ini:

c:\wamp\bin\apache\apache2.2.8\bin\php.ini

Find the following lines (fresh from a new install):

; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"


Uncomment the second line (remove the semicolon) and change it to:

include_path = ".;c:\wamp\bin\php\php5.2.5\PEAR"

Restart Apache.

Your mail script should now work with PEAR::Mail.

It is important to test first the mail connection to the SMTP server you are using from the simplest possible script, perhaps just using the mail() function in PHP.  If you experience connction problems, sort them out first.  You can fire off STMP commands from the DOS box, following the sample available in the article about SMTP in Wikipedia .

In addition, if you want to use the Mail class from the command line interface (CLI), you need to add the PEAR folder to include_path in the file c:\wamp\bin\php\php5.2.5\php.ini. Sending emails from scheduled scripts like database backup is very handy.

In both configurations, in case you were to use just the mail() function in PHP, you must edit the php.ini file and make sure that the the SMTP parameter contains the domain name or IP address of the STMP server to which your application sends the messages.

[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
;sendmail_from = This e-mail address is being protected from spam bots, you need JavaScript enabled to view it


However, scripts using the PEAR::Mail class can set the host address as a parameter to the Mail function.

Be careful to inspect in your code the email addresses entered by the visitors to your website into online forms so that they enter using the email address in a valid format.   You can save yourself from many headaches and avoid surprises in from mail injection attempts. Do some reading on email injection and how to prevent it.
 

Last Updated ( Saturday, 22 March 2008 )