PEAR is a perfect choice to facilitate your email marketing campaigns. However, since PEAR is not installed by default on our servers, you need to do a little setup first. Follow the steps bellow to install and configure PEAR.
NB: You can only do this installation yourself if you have SSH access. If not, please contact Support to install PEAR for you.
NB: In the example code and screen output we use the hosting account name “ninefortwobe” since we install PEAR on the hosting ninefortwo.be. Make sure you replace ‘ninefortwobe’ with your account name instead. This should be the domain name of the hosting without any dots (‘.’) in it.
You have to run the installation of PEAR from the root of the hosting (the directory above the “www” folder). You can go to this folder via the symlink “site”:
First, the go-pear.phar package must be downloaded to initiate the installation:
curl -O http://pear.php.net/go-pear.phar php go-pear.phar
Second, after you have the package, you can proceed with the installation. Just press Enter to continue.
server@com-linssh001:~# php go-pear.phar 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. 1. Installation base ($prefix) : /data/sites/web/ninefortwobe/pear 2. Temporary directory for processing : /tmp/pear/install 3. Temporary directory for downloads : /tmp/pear/install 4. Binaries directory : /data/sites/web/ninefortwobe/pear/bin 5. PHP code directory ($php_dir) : /data/sites/web/ninefortwobe/pear/share/pear 6. Documentation directory : /data/sites/web/ninefortwobe/pear/docs 7. Data directory : /data/sites/web/ninefortwobe/pear/data 8. User-modifiable configuration files directory : /data/sites/web/ninefortwobe/pear/cfg 9. Public Web Files directory : /data/sites/web/ninefortwobe/pear/www 10. Tests directory : /data/sites/web/ninefortwobe/pear/tests 11. Name of configuration file : /data/sites/web/ninefortwobe/.pearrc 1-11, 'all' or Enter to continue:
PEAR then wants to change the include_path of the CLI. Do not do this – just press ‘n’ to skip that.
Beginning install... Configuration written to /data/sites/web/ninefortwobe/.pearrc... Initialized registry... Preparing to install... installing phar:///site/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar... installing phar:///site/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar... installing phar:///site/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.4.tar... installing phar:///site/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar... installing phar:///site/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar... install ok: channel://pear.php.net/Archive_Tar-1.3.7 install ok: channel://pear.php.net/Console_Getopt-1.3.0 install ok: channel://pear.php.net/Structures_Graph-1.0.4 install ok: channel://pear.php.net/XML_Util-1.2.1 install ok: channel://pear.php.net/PEAR-1.9.4 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: </data/sites/web/ninefortwobe/pear/share/pear> If the specified directory is also not in the include_path used by your scripts, you will have problems getting any PEAR packages working. Would you like to alter php.ini </etc/php5/cli/php.ini>? [Y/n] : n
This is what you see next. Press ‘Enter’ to proceed
I will add a workaround for this in the 'pear' command to make sure the installer works, but please look over your php.ini or Apache configuration to make sure /data/sites/web/ninefortwobe/pear/share/pear is in your include_path. Current include path : .:/usr/share/php:/usr/share/pear Configured directory : /data/sites/web/ninefortwobe/pear/share/pear Currently used php.ini (guess) : /etc/php5/cli/php.ini Press Enter to continue:
Finally, you get the confirmation of the installation:
** WARNING! Old version found at /data/sites/web/thijsferynnet/pear/bin, please remove it or be sure to use the new /data/sites/web/thijsferynnet/pear/bin/pear command The 'pear' command is now at your service at /data/sites/web/thijsferynnet/pear/bin/pear ** The 'pear' command is not currently in your PATH, so you need to ** use '/data/sites/web/thijsferynnet/pear/bin/pear' until you have added ** '/data/sites/web/thijsferynnet/pear/bin' 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!
Use the package manager
Now that PEAR is installed, you can install the packages. To get the mail functionality, run the following command (Don’t forget to change ‘ninefortwobe’ with your account name, without the ‘.’):
/data/sites/web/ninefortwobe/pear/bin/pear install mail
This is the output you get:
Did not download optional dependencies: pear/Net_SMTP, use --alldeps to download automatically pear/Mail can optionally use package "pear/Net_SMTP" (version >= 1.4.1) downloading Mail-1.2.0.tgz ... Starting to download Mail-1.2.0.tgz (23,214 bytes) ........done: 23,214 bytes install ok: channel://pear.php.net/Mail-1.2.0
The packages themselves are in /data/sites/web/ninefortwobe/pear/share/pear.
To use PEAR effectively, you need to adjust your include_path. Developers can edit it in their code with this well-known trick:
<?php set_include_path(implode(PATH_SEPARATOR, array( realpath( '../pear/share/pear'), get_include_path(), )));
Or you can add include_path in the ‘PHP settings’ section of the control panel of your hosting in the control panel:
Hint: You can do that at My Products >> Web Hosting >> Hosting Details >> PHP Settings >> Include paths
Once PEAR and Mail module is installed you must also install the module Net_SMTP if you want to send emails using a relay server with authentication. Use the following command:
/site/pear/bin/pear install Net_SMTP
Below you have an example of a PHP script for sending emails with authentication:
NOTE: on a Linux hosting all SMTP traffic going through port 25 is redirected to the default relay server of the hosting cluster (relay.webhosting.be). To make sure you use your own SMTP server you need to use an alternative port instead (2525 in the example below).
<?php include("Mail.php"); /* mail setup recipients, subject etc */ $recipients = "firstname.lastname@example.org"; $headers["From"] = "email@example.com"; $headers["To"] = "firstname.lastname@example.org"; $headers["Subject"] = "Email subject"; $mailmsg = "Hello, This is a check."; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "mailing.ninefortwo.be"; $smtpinfo["port"] = "2525"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "id111111_ninefortwobe"; $smtpinfo["password"] = "$tr0ngPa$$worD"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); /* Ok send mail */ $mail_object->send($recipients, $headers, $mailmsg); ?>