Hi guys,
first of all i am new to php, so please bear with me.
I have this requirement wherein i need to automatically create email accounts with my hosting provider through my website's php code.
I have a linux hosting account with cpanel interface (its bluehost.com btw, if that matters).
I came across this cpanel xml api which lets you make api calls to access the function of cpanel through your code. I've donwloaded the api file ('xmlapi.php') and followed the forums and all to write my small php code to call the api to create an email account.
Here's the setup
1) i've uploaded 'xmlapi.php' to root folder of my domains hosting folder
2) i've uploaded another php file 'emailaccount.php' to the root folder
Below is the code inside emailaccount.php

<?php

    include_once "xmlapi.php" ;
    $ip = "mydomain.com";/*my main domain for the hosting account*/
    $domain = "mydomain.com";/*i want to create ckchaudhary@mydomain.com*/
    $root_pass = "my_cpanels_password";


    $xmlapi = new xmlapi($ip);
    $xmlapi->set_auth_type("pass");
    $xmlapi->set_output("json");
    $xmlapi->password_auth("my_cpanels_login_name",$root_pass);
    $xmlapi->set_port(2083);
    //$xmlapi->password_auth($domain,$root_pass);

    $xmlapi->set_debug(1);

    $acct = array( 'username' => "ckchaudhary", 'password' => "Pass1234", 'domain' => $domain);
    try{
        $response =  $xmlapi->createacct($acct);
        print_r($response);
        echo "<hr/><br/>Email account created successfuly";
    }
    catch(Exception $e){
        echo "<strong>Error : </strong>" . $e->getMessage();
    }
    ?>

The Problem:
$response is always blank. try block is always executed successfuly. But when i login to my cpanel i dont see the new email account listed !
Has anyone worked with cpanel api before? It'd be a great help if someone cud tell me what i need to do

Recommended Answers

All 2 Replies

Doesn't your webhost provide any documentation for this? Have you contacted them to ask whether or not it is supported at all?

for anyone accidently coming to this dead thread: i did get it working. Here's the link to my blog post about it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.