The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Create new email account using php script.

Discussion in 'E-mail Discussions' started by chetanmadaan, Mar 15, 2012.

  1. chetanmadaan

    chetanmadaan Member

    Jun 18, 2010
    Likes Received:
    Trophy Points:
    hi -

    we have a website and we need assign every new user to create have an email account.

    I know for the mysql database... we can give a root used enough rights and that user will be able to create databases.

    is that the same Case for email??

    can you use a simple php script to create email account on our cpanel/WHM.

    we have a dedicated server.

  2. rlesterphx

    rlesterphx Member

    Jul 22, 2010
    Likes Received:
    Trophy Points:
    I don't know your technical level, but here's a quick run-through.

    First you're going to need to download the PHP XML API Class:

    Upload it to your server and include it in the script you're building to create email accounts. Here is some sample code adapted from a script I made:
    $ip = ""; //your server's IP
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("serverusername","password"); //the server login info for the user you want to create the emails under
    $params = array(domain=>'', email=>'newemailusername', password=>'newpassword', quota=>25); //quota is in MB
    $addEmail = json_decode($xmlapi->api2_query("serverusername", "Email", "addpop", $params), true);
    	echo "success";
    else {
    	echo "Error creating email account:\n".$addEmail['cpanelresult']['data'][0]['reason'];
    Additional notes:
    -Make sure you have the Services_JSON extension installed. You can do this in WHM under Module Installers>PHP Extensions and search for JSON.
    -If you get an error saying SSL support is not available follow the instructions on this post to enable SOAP with SSL:
    -A whole lot more info and things you can do with the API now that you have it installed:
    Calling API 2 Functions
    WebHome < ApiDocs/Api2 < TWiki

Share This Page