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"a=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!!
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 . ""a=".$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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With