How to install PHP PEAR::Mail Class in WAMP2
Posted by ravi | Posted in PHP | Posted on 05-08-2009
Tags: MAIL, PEAR, PHP
2
Q.How to install PHP PEAR::Mail Class in WAMP2 ?
A:The Solution assumes that you’ve already installed the latest WAMPSERVER
Go to the PHP installation directory(this is C:\wamp\bin\php\php5.2.6 on my machine) and run the go-pear.bat file.A command prompt window will be opened with the following message:
(system|local) [system] :
Just Press Enter key.
Now it shows the message below:
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type ‘all’ to change all of them or simply press Enter to
accept these locations.
2. Temporary directory for processing : C:\wamp\bin\php\php5.2.6\tmp
3. Temporary directory for downloads : C:\wamp\bin\php\php5.2.6\tmp
4. Binaries directory : C:\wamp\bin\php\php5.2.6
5. PHP code directory ($php_dir) : C:\wamp\bin\php\php5.2.6\pear
6. Documentation directory : C:\wamp\bin\php\php5.2.6\docs
7. Data directory : C:\wamp\bin\php\php5.2.6\data
8. User-modifiable configuration files directory : C:\wamp\bin\php\php5.2.6\cfg
9. Public Web Files directory : C:\wamp\bin\php\php5.2.6\www
10. Tests directory : C:\wamp\bin\php\php5.2.6\tests
11. Name of configuration file : C:\wamp\bin\php\php5.2.6\pear.ini
12. Path to CLI php.exe : C:\wamp\bin\php\php5.2.6\.
1-12, ‘all’ or Enter to continue:
Check the paths once and again press enter
This will install the PEAR package and shows the following messages:
Configuration written to C:\wamp\bin\php\php5.2.9-1\pear.ini…
Initialized registry…
Preparing to install…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.3.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.7.2.tar…
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar.
..
pear/PEAR can optionally use package “pear/XML_RPC” (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.3
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.7.2
PEAR: Optional feature webinstaller available (PEAR’s web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR’s PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR’s PHP-GTK2-based installer)
PEAR: To install optional features use “pear install pear/PEAR#featurename”
******************************************************************************WARNING! The include_path defined in the currently used php.ini does not contain the PEAR PHP directory you just specified:Would you like to alter php.ini <C:\wamp\bin\apache\apache2.2.11\bin\php.ini>? [Y/n] :
Press N, as pressing Y doesn’t edit the actual php.ini file that will be used by WAMPServer.
This will display the following:
C:\wamp\bin\php\php5.2.9-1\pear is in your include_path.
Current include path : .;C:\php5\pear
Configured directory : C:\wamp\bin\php\php5.2.9-1\pear
Currently used php.ini (guess) : C:\wamp\bin\apache\apache2.2.11\bin\php.ini
Press Enter to continue:
** The ‘pear’ command is not currently in your PATH, so you need to
** use ‘c:\wamp\bin\php\php5.2.9-1\pear.bat’ until you have added
** ‘C:\wamp\bin\php\php5.2.9-1? to your PATH environment variable.
Run it without parameters to see the available actions, try ‘pear list’
to see what packages are installed, or ‘pear help’ for help.
For more information about PEAR, see:
http://pear.php.net/faq.php
http://pear.php.net/manual/
Thanks for using go-pear!
Now, you’ve successfully installed basic PEAR package. To actually see the package in work, first of all you’ve to edit your ini file. So open the c:\wamp\bin\apache\apache2.2.11\bin\php.ini file and search for
;include_path = “.;c:\php\includes”
modify it to:
include_path = “.;c:\wamp\bin\php\php5.2.9-1\PEAR”
In c:\wamp\bin\php\php5.2.9-1, copy the file pear.bat to C:\WINDOWS\system32. Alternatively you can add C:\wamp\php to your windows PATH environment variable to expose this file globally. This step helps you to run the pear commands directly from the DOS with out traversing to the exact path every time.
Ok, now restart apache and goto command and type pear . If you see a message similar to the one below, then your PEAR installation is successful other wise…go through the steps above and check for any errors:
build Build an Extension From C Source
bundle Unpacks a Pecl Package
channel-add Add a Channel
channel-alias Specify an alias to a channel name
channel-delete Remove a Channel From the List
channel-discover Initialize a Channel from its server
channel-info Retrieve Information on a Channel
channel-update Update an Existing Channel
clear-cache Clear Web Services Cache
config-create Create a Default configuration file
config-get Show One Setting
config-help Show Information About Setting
config-set Change Setting
config-show Show All Settings
convert Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff Run a “cvs diff” for all files in a package
cvstag Set CVS Release Tag
download Download Package
download-all Downloads each available package from the default channel
info Display information about a package
install Install Package
list List Installed Packages In The Default Channel
list-all List All Packages
list-channels List Available Channels
list-files List Files In Installed Package
list-upgrades List Available Upgrades
login Connects and authenticates to remote server
logout Logs out from the remote server
makerpm Builds an RPM spec file from a PEAR package
package Build Package
package-dependencies Show package dependencies
package-validate Validate Package Consistency
pickle Build PECL Package
remote-info Information About Remote Packages
remote-list List Remote Packages
run-scripts Run Post-Install Scripts bundled with a package
run-tests Run Regression Tests
search Search remote package database
shell-test Shell Script Test
sign Sign a package distribution file
uninstall Un-install Package
update-channels Update the Channel List
upgrade Upgrade Package
upgrade-all Upgrade All Packages
Usage: pear [options] command [command-options] <parameters>
Type “pear help options” to list all options.
Type “pear help shortcuts” to list all command shortcuts.
Type “pear help <command>” to get the help for the specified command.
Ok. Now, on to the MAIL package installation. To install the PEAR mail package, all that you’ve to do is open the command prompt and type pear install –alldeps mail.
This installs the PEAR::Mail package with all the dependencies.
To test the installation, type pear list on command prompt and you should see the message as below:
=========================================
PACKAGE VERSION STATE
Archive_Tar 1.3.2 stable
Auth_SASL 1.0.2 stable
Console_Getopt 1.2.3 stable
Mail 1.1.14 stable
Net_SMTP 1.3.2 stable
Net_Socket 1.0.9 stable
PEAR 1.7.1 stable
Structures_Graph 1.0.2 stable
That’s it…you’re ready to send mails using PHP pear package. Here is a starter example:
require_once “Mail.php”;
$from = “sender<sender@yourdomain.com>”;
$to = “reciever <reciever@recieverdomain.com>”;
$subject = “Hi!”;
$body = “Hi,\n\nHow are you?”;
$host = “smtp.yourdomain.com”;
$username = “sender@yourdomain.com”;
$password = “senderpassword”;
$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>”);
}
?>
Please note that naming this file as mail.php will cause error saying that class Mail is undefined on line 16. So take care that you’ve named it something else.
To send mail using SSL authentication, you’ve to take some extra steps after the above.
Now the code needs extra arguments to be passed. Let’s assume we want to use a Google mail account:
$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);
Post a comment if you still have some problems.
cheers,
ravi.
references:


After installing pear, to install the mail.php class, the correct command is “pear install –alldeps mail” or “pear install -a mail”. The above is missing the 2nd dash before “alldeps”.
[...] Once it’s all set up you can run off some test emails to see how things work. Here is a link to another tutorial for you. The actual tutorial portion didn’t make quite as much sense as the previous one [...]