cPanel: Class for creating email account and mail forwarder

cpanel_logoThis class can be used to create email account and mail forwarders using PHP, without logging to cPanel. It is an extension of script made by You can access the original link from here And it is also a modified version of the class “cpmail” which was coded by Md. Zakir Hossain (Raju), How to configure:

  1. Download the zipped file.
  2. Unzip the file. This file contains the class file and an example file.
  3. Open the class file and change these variables –
    • $currentTheme – Your cPanel theme
    • $userName – Your cPanel user name
    • $password – Your cPanel password
    • $domain – Your cPanel domain
    • $cPanelPort – Your cPanel port [optional]
  4. Include the class in the file where you want to use it.


// include the class file
// create an instanse of the class
$cp = new CPMailManager();
// create an email account
$cp->createEmail('sadat', 'sadat123', 10);
if($cp->status) //account created successfully
     echo 'Mail created successfully';
     echo $cp->message;
// create mail forwarder
$cp->createForwarder('sadat', '[email protected]');
echo '' . $cp->message;
// delete mail forwarder
$cp->deleteForwarder('sadat', '[email protected]');
echo '' . $cp->message;
// delete email account
echo '' . $cp->message;