Tag: PEAR

PEAR Mail – Checking If Mail Sent

PEAR Mail & mail_mime is absolutely fantastic for sending multi-part mime emails and requires absolutely no effort. Probably, the best part of PEAR Mail & mail_mime is not having to deal with mime boundaries.

I often see incorrect code for handling whether the message successfully sent or not. To check if the message is sent we should do something like the following.

$isSent = $mail->send(...);
if (PEAR::isError($isSent)) {
// error handling goes here
} else {
// successfully sent code goes here.
}

If we simply use the following code, we’ll always have a true condition because $isSent won’t be set to null.

$isSent = $mail->send(...);
if ($isSent) {
// successfully sent code goes here.
//Unfortunately this will always be called
} else {
//code here will never actually be executed.
}

Hope this helps!

Installing PEAR on BlueHost

PEAR as I’m sure you’re aware stands for “PHP Extension and Application Repository” and is one of the leading frameworks for reusable components.

Installing BlueHost can be easily be accomplished using the Fantastico located inside your Cpanel access. The configuration of PEAR can be quite a challenge though!

The PEAR installation as I’m sure you’ve seen already is extremely simple. Configuration will require modifying your php.ini file. If you don’t have a php.ini file in /public_html you will need to follow the following steps.

  1. Log into Cpanel. Click PHP Config
  2. Click Install PHP.INI Master File

Now that you have a php.ini file that we can modify you will need to find the line include_path. In my php.ini file it is line 503. Change the include_path to the following making not that you will need to replace the # number with your potential number, and {{YOURBLUEHOSTUSERNAME}} should be your bluehost username without the domain name.

If you don’t know these details you can find them under the main page of Cpanel under Stats, Home Directory.


include_path = ".:/usr/lib64/php:/usr/lib/php:/home#/{{YOURBLUEHOSTUSERNAME}}/php"

Some of the core PEAR packages aren’t always installed. For example, I’ve had to go back into the PEAR Config form and search for Mail and install it.

Hope this helps!