Reputation: 677
I am trying to create an email account via script without logging into the cpanel. Here is the script I am using
http://www.zubrag.com/scripts/cpanel-create-email-account.php
Hosting provider is bluehost
I am getting this error
Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode
safe mode is off in my ini file.
Here is the credential area that the script is using
// cPanel info
$cpuser = 'example.com'; // cPanel username
$cppass = 'my_cpanel_pass'; // cPanel password
$cpdomain = 'example.com'; // cPanel domain or IP
$cpskin = 'x'; // I have tried x and also bluehost here
// Default email info for new email accounts
// These will only be used if not passed via URL
$epass = 'my_cpanel_pass'; // email password
$edomain = 'example.com'; // email domain (usually same as cPanel domain above)
$equota = 20; // amount of space in megabytes
The following code is sending me the errors/warnings
$f = fopen ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddpop.html?email=$euser&domain=$edomain&password=$epass"a=$equota", "r");
if (!$f) {
$msg = 'Cannot create email account. Possible reasons: "fopen" function allowed on your server, PHP is running in SAFE mode';
break;
}
The warning I'm getting is
Warning: fopen(http://[email protected]:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=example.com&password=SmallAn123!&quota=20): failed to open stream: HTTP request failed! HTTP/1.1 401 Access Denied in E:\Web Softs\wamp\www\clnt5\cpemail.php on line 81
If I print all the stuff between fopen() I get this
http://cpanel_user_name:[email protected]:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=mydomain.com&password=SmallAn123!"a=20
I have googled a lot to fix this. Any help or an alternate script that can help me achieve this will be much appreciated.
Upvotes: 0
Views: 707
Reputation: 377
If you have cpanel username and password then you should use cpanel API to create email accounts and for lot more functionalities too rather than these get request.
require_once 'xmlapi.php';
$xmlapi = new \xmlapi($cpanel_domain);
$xmlapi->password_auth($cpanel_username,$cpanel_password);
$xmlapi->set_port('your domain port will be here');
$api2args = array();
$result = $xmlapi->api1_query($cpanel_password, 'CustInfo', 'getemail', $api2args);
// until here you will get confirmation of your connected cpanel with cpanel api
// then create cpanel as below
$api2args = array(
'domain' => $domain,
'email' => $email_address_to_create,
'password' => $email_password,
'quota' => '2048', // quota for email you want to set
);
$result = $xmlapi->api2_query($cpanel_username, 'Email', 'addpop', $api2args);
if(isset($result->error) && $result->error!=""){
// error can be recorded here
}
else{
// email account get created
}
Upvotes: 0