Updated: 22 October 2026 · Applies to: cPanel PHP PEAR Packages (cPanel 82 and later, documented); tested with PHP 8.4.27, PEAR 1.10.16, PEAR Mail 2.0.0 and Composer 2.8.8 on Debian 13

PHP cannot find Mail.php because cPanel installs your own PEAR packages in a folder inside your home directory (usually /home/USERNAME/php), and that folder is not on PHP's include path. Add it to the include path at the top of your script, before require_once 'Mail.php';, and PEAR Mail loads.

The error you see

Without the extra path, PHP stops with an error like this (from our lab test, user alice):

Output:

PHP Warning:  require_once(Mail.php): Failed to open stream: No such file or directory in /home/alice/public_html/without.php on line 2
PHP Fatal error:  Uncaught Error: Failed opening required 'Mail.php' (include_path='.:/usr/share/php') in /home/alice/public_html/without.php:2

The include_path in the message shows where PHP looked. Your own PEAR folder is missing from that list.

Fix: add your PEAR folder to the include path

  1. Log in to cPanel and open PHP PEAR Packages (in the Software section). The Module Include Path section shows the folder where cPanel stores your packages, and Using Your PHP Extension and Application shows the code to add to your script. If you cannot find the icon, your host may have turned it off in WHM's Feature Manager.
  2. Make sure Mail is listed as installed. If it is not, type Mail in the install box and click Install Now. In our test, installing Mail also pulled in Net_SMTP, Net_Socket and Auth_SASL.
  3. Add these lines at the very top of the script that sends mail. Replace USERNAME with your cPanel username, or use the exact path shown under Module Include Path:
<?php
$path = '/home/USERNAME/php';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Mail.php';
  1. Load the page or run the script again. Mail.php now loads.

A short test script that only creates an SMTP mailer (it does not send anything) confirms the setup. Use your own mail server, mailbox and password:

<?php
$path = '/home/USERNAME/php';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);

require_once 'Mail.php';

$mailer = Mail::factory('smtp', [
    'host'     => 'mail.example.com',
    'port'     => 587,
    'auth'     => true,
    'username' => 'info@example.com',
    'password' => 'your-mailbox-password',
]);
echo get_class($mailer), "\n";
echo get_include_path(), "\n";

Output in our lab (the second line shows your folder added at the end):

Mail_smtp
.:/usr/share/php:/home/alice/php

Append the path, do not replace it

Keep get_include_path() . PATH_SEPARATOR in the line. If you set only your own folder, PHP finds Mail.php but can no longer find the base PEAR class it needs:

Output:

PHP Warning:  require_once(PEAR.php): Failed to open stream: No such file or directory in /home/alice/php/Mail.php on line 48
PHP Fatal error:  Uncaught Error: Failed opening required 'PEAR.php' (include_path='/home/alice/php') in /home/alice/php/Mail.php:48

If you see the PEAR.php error even with the appended path, the server's own PEAR is not on the default path. Install the PEAR package in PHP PEAR Packages as well, so PEAR.php is placed in your own folder. In our lab, installing the PEAR package into the same folder with the pear command fixed it.

Alternative: install PEAR Mail with Composer

If you have SSH access and Composer, you do not need the include path at all. In your project folder, run:

composer require pear/mail

Then load Composer's autoloader instead of Mail.php:

<?php
require __DIR__ . '/vendor/autoload.php';

$mailer = Mail::factory('smtp', ['host' => 'mail.example.com', 'port' => 587]);

In our test Composer installed pear/mail version 2.x and the script worked with an empty include path.

Still not sending?

If you would rather have someone set this up for you, our team can help through Hire an Expert.

Official documentation: cPanel PHP PEAR Packages and PHP set_include_path.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Managed cPanel VPS

cPanel included; we handle updates, security and monitoring.

Server management

on-demand administration, hardening, migrations and monitoring.

Was this answer helpful?

Still stuck? Open a ticket