Question

I am trying to create email accounts in the bluehost cpanel using php script. I tried XML API for this but it gives "Access denied" error.

Now I am trying to do the same using following code, but no success. I am able to login to CPanel but unable to crate email account.

$login = "https://my.bluehost.com/cgi/account/cpanel";
$time=time();
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $login);
curl_setopt($c, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($c, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($c, CURLOPT_POST, 1);
curl_setopt($c, CURLOPT_POSTFIELDS, "ldomain=$username&lpass=$password&l_redirect=/cgi-bin/cplogin&l_server_time=$time&l_expires_min=0");
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
$login_done1 = curl_exec($c);
print_r($login_done1);




   $email= "https://$cpanel:2083/frontend/bluehost/mail/doaddpop.html";
    curl_setopt($c, CURLOPT_URL, $email);s
    curl_setopt($c, CURLOPT_COOKIEJAR, "cookies.txt");
    curl_setopt($c, CURLOPT_COOKIEFILE, "cookies.txt");
    curl_setopt($c, CURLOPT_POST, 1);
    curl_setopt($c, CURLOPT_POSTFIELDS, "email=ddddd&domain=test.org&password=test@1617&password2=test@1617&quota=250&new_email_submit=Create");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
    $login_done2 = curl_exec($c);
    print_r($login_done2);

Any help appreciated!!

Was it helpful?

Solution

I've dealt with bluehost about this issue, and the main problem is the fact that Bluehost accounts don't give access to su. super user. So you're not able to access Cpanel from any back doors, not even your own. Which is a major pain if a site owner wants to allow users to create email accounts.

OTHER TIPS

I've figured out a way to deal with the cpanel in BlueHost and create an email account

$account_user would be the default username to log in to Blue Host; It might be the same as $cp_user but it definitely does not allow it to be root.

 private function createEmail($email, $password) {
    $cp_user = "USERNAME";
    $cp_pwd = "PASSWORD";
    $domain = "yourdomain.com"
    $quota = "500" // This is in Megabytes. 0 Would be unrestricted email box size.
    $account_user = "username"
    $url = "DOMAIN N OR IP :2087 //Your Port";
    $php = "/json-api/cpanel?cpanel_jsonapi_user=".$account_user."&cpanel_jsonapi_version=2&cpanel_jsonapi_module=Email&cpanel_jsonapi_func=addpop&email=" . $email . "&password=" . $password . "&quota=".$quota."&domain=".$domain;
    $string1 = "https://" . $cp_user . ":" . $cp_pwd . "@" . $url . $php;
    $blueHost = fopen($string1, "r");
    fclose($blueHost);
    return $blueHost;
}

Just took some trial and error and inspecting the JSON API call when creating an email user in Bluehost.com after logging-in. Hope this helps some one as Blue Host does not have any support and i had trouble otherwise setting up email accounts.

you can achieve this directly inside the chrooted environment (SSH must be enabled via Bluehost / Hostmonster CPANEL). Just specify 127.0.0.1 as $cpanel and you dont ever need any previous authentication with the https://my.bluehost... landing page. It works with shared hostings as well as dedicated.

Although you will need to authenticate via GET:

    curl http://username:password@127.0.0.1:2082/frontend/bluehost/mail/doaddpop.html?blabla

Here's an useful overview you can translate in your language. Please google for doaddfwd.html dodelpop, dodelfwd etc etc. http://beto.euqueroserummacaco.com/blog/criando-contas-de-email-no-cpanel-com-curl/

Another method that's been presented was to allow the user to create their desired email and store that into a database like mysql. Then create and set a cron job that would periodically check that database for new emails and create the email into the cpanel through the cron job. It's actually quite cumbersome to create email accounts in bluehost. 2 reasons, 1 is like I mentioned before about the -su block. But also they're provided a cpanel resell. So it's really not a full license of cpanel. Because cpanel itself does have functions for creating email accounts and including creating subdomains. So far only ones I've found that offer a real cpanel is Hostgator and Godaddy, I prefer bluehost though. Just about only other way to create email accounts is to create them in the actual file structure. But it can get blown out real quick with all the encryptions and file structure.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top