How to install and Setup php-pear mail on CentOS or RHEL

PEAR::Mail is one from php classes/components and it provides advanced interfaces to PHP applications and programs for sending emails. Today am going to explain the steps to install php-pear and Mail – Setup Guide on a CentOS or RHEL based server.
PEAR::Mail is NOT part of a base PHP installation, it is an advanced framework that needs to be installed separately on the web server that is running your website.

First of all Check PhPear is already installed on server or not:

rpm -qa|grep php-pear

If it is not installed on your webserver, please install it by executing the following command from the server CLI.

yum install php-pear

Test if it’s installed correctly

rpm -qa|grep php-pear

Install Php-mail extension by executing the following command:

pear install Mail

Restart web-server

service httpd restart


Now to send a message using PEAR::Mail through AuthSMTP first of all create a file called authsmtp-test.php on your web server containing the following code:

$recipients = '[email protected]'; //CHANGE
$headers['From']= '[email protected]'; //CHANGE
$headers['To']= '[email protected]'; //CHANGE
$headers['Subject'] = 'Test message';
$body = 'Test message'; // Define SMTP Parameters
$params['host'] = '';
$params['port'] = '25';
$params['auth'] = 'PLAIN';
$params['username'] = 'USERNAME'; //CHANGE
$params['password'] = 'PASSWORD'; //CHANGE

/* The following option enables SMTP debugging and will print the SMTP 
conversation to the page, it will only help with authentication issues,
if PEAR::Mail is not installed you won't get this far. */

$params['debug'] = 'true'; // Create the mail object using the Mail::
factory method
$mail_object =& Mail::factory('smtp', $params); // Print the parameters
 you are using to the page

foreach ($params as $p){
echo "$p<br />";

// Send the message
$mail_object->send($recipients, $headers, $body);


Step 2

Change the following lines:

$recipients to your email address
$headers['From'] to your email address
$headers['To'] to your email address
'USERNAME' to your AuthSMTP username
'PASSWORD' to your AuthSMTP password

Save the file to your web server.

Open a web browser and view the uploaded authsmtp-test.php file on the browser.

If it was successful you will see at the end of the conversation a section that reads ‘Message accepted for delivery’

This means that you can continue to integrate this into your form / application.
Recommended to store the username and password variable definitions in a separate PHP file outside your public web directory and reference back to it.

Enable or disable SSL

Currently PEAR::Mail has SSL/TLS enabled for SMTP and it will always try to create a secure connection, there are no configurations to change this setting.

To disable SSL/TLS in PEAR::MAIL, you will need to access the source files for the framework on your server


Edit the file – /pear/Net_SMTP/Net/SMTP.php
Find the line with the following content (approximately line 590):

function auth($uid, $pwd, $method = '', $tls = true, $authz = '')

Replace this with:

function auth($uid, $pwd, $method = '', $tls = false, $authz = '')

So changing ‘$tls’ from ‘true’ to ‘false’

Save the file.

That’s all to do, Please Give your opinion below if you experience any issues or to discuss your ideas and experiences.