Search code examples
phpcpanelwebmail

Create webmail account with PHP


How can i create webmail accounts using PHP? I am using cPanel. I tried several scripts but none of them seem to work, can someone give me some insight with this?

Thank you very much!!


Solution

  • You need the Cpanel XML API class. Download it here:

    http://sdk.cpanel.net/lib/xmlapi/php/cp_xmlapi_php_v1.0.5.tar.gz

    It comes with usage examples but this can get you started:

    include('xmlapi.php');
    
    $account = "Cogicero";
    $account_pass = "password";
    $ip = "xxx.xxx.xxx.xxx";
    
    $email_user = "cogicero";
    $email_password = "password";
    $email_domain = "cogicero.com";
    $email_quota = "100";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user,   $email_password, $email_quota, $email_domain) );
    

    Edit: If you need more information on the API, see this: http://docs.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/XmlApi