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://...#example.com:2082/frontend/x/mail/doaddpop.html?email=asif.k&domain=example.com&password=SmallAn123!"a=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:my_cpanel_pass#example.com: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.
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
}
Related
Hello i want to create ftp for particular users.. I have searched on google but nothing found. So i have decided to put question on stackoverflow. I have tried below code but not working at all :-
$cpaneluser = "xxxxx"; // i have entered my cpanel user
$cpanelpass = "xxx"; //pwd
$domain = "testing.domain.com"; //here i have entered the domain
$fuser = "testing#domain.com";
$fpass = "mypwd";
$homedir = "/direcctorypath";
$url = "http://$cpaneluser:$cpanelpass#$domain:2082/json-api/cpanel?";
$url .= "cpanel_jsonapi_version=2&cpanel_jsonapi_module=Ftp&cpanel_jsonapi_func=addftp&";
$url .= "user=$fuser&pass=$fpass&homedir=$homedir"a=0";
var_dump($url);
$result = file_get_contents($url);
var_dump($http_response_header);
if ($result === FALSE)
die("ERROR: FTP Account not created. Please make sure you passed correct parameters.");
echo $result;
SEE OUTPUT
Every time its output coming FTP Account not created. Please make sure you passed correct parameters..
But i have entered the correct details. i Don't know why its not working.
So later on i have decide lets do with exec command but that also not working
Ref Url :- Creating FTP user accounts using FTP on server
exec("adduser -c 'testing#domain.com' -m testing123"); // this is not working at all
After checking above url i have added the username and password of ftp account. But i have one doubt where i passed the cpanel useranme and password in exec function. Can anyone tell me how to create ftp account of a user. Thanks in advance
I'm working on a WHM API and want to find the cPanel username by passing the domain name.
NOTE: I've the credentials of WHM.
There is no such documentation exists here https://documentation.cpanel.net/pages/viewpage.action?pageId=1507786
So, is there a way to achieve do so?
Update:
Now, I'm using xmlapi.php and here is what I tried so far.
require_once(base_path() . "/vendor/cpanel_api/xmlapi.php");
$ip = env('SERVER_IP', "127.0.0.1"); //your server's IP
$xmlapi = new \xmlapi($ip);
$xmlapi->password_auth(env('CPANEL_USER', "root"),env('CPANEL_PASSWORD', "")); //the server login info for the user you want to create the emails under
$xmlapi->set_output('json');
$xmlapi->set_debug(1);
$params = array('domain'=>$domain, 'searchtype'=>'domain'); //quota is in MB
$res = json_decode($xmlapi->api2_query('root', "listaccts", "", $params), true);
print_r($res);
in $xmlapi->api2_query method, there are 4 arguments
cPanel Username
WHM Module Name
Function under the Given Module in step 2
parameters, that'll be passed to the function in step 3
I have to find out the cPanel Username, so, I wrote the 'root' for now. but no success
Please give a try with cPanel API.
Here are the some useful docs of API.
https://documentation.cpanel.net/display/SDK/Guide+to+cPanel+API+2
https://documentation.cpanel.net/display/SDK/Guide+to+WHM+API+1
I am trying to use cPanel xml api to add ip addresses to the mysql remote access host list.
If I use this...
$newdomain = "12.345.45.678";
$myemails = $xmlapi->api2_query($account, "MysqlFE", "authorizehost", array('host'=>$newdomain) );
I can in fact add the ip to the remote host access list. I verified by logging into cPanel and checking.
When I try to access the database remotely, I am blocked. ???? like I have not whitelisted my ip ??
If I log into cPanel and remove the ip address and add it manually(the exact same ip)...then test my remote connection, and it works.
Am I missing something here?
The xmlapi adds the ip successfully, but I still can't get a remote connection.
If it helps at all, my whitelist already has some ip addresses that were added manually. So, it is not an empty record.
<?php
require_once("xmlapi.php");
$ip = 'website ip address here';
$account = 'cpanel username here';
$domain = 'mysite.com';
$passwd = 'cpanel password here';
$xmlapi = new xmlapi($ip);
$xmlapi->password_auth($account, $passwd);
$xmlapi->set_port(2083);
$xmlapi->set_output("simplexml");
$newAuthIP = "123.45.67.890"; <----- sanitized value from a form post
$myemails = $xmlapi->api2_query($account, "MysqlFE", "authorizehost", array('host'=>$newAuthIP) );
?>
I'm using XML api 2
$xmlapi = new xmlapi('MY IP Address');
$xmlapi->password_auth("root",'My Cpanel password');
$xmlapi->set_output("json");
$xmlapi->set_debug(1);
print $xmlapi->api2_query($account, "Email", "listpopswithdisk" );
But it's giving this error.
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
How to resolve this error.
Check your port settings -
$xmlapi->set_port(2083); //2082 if not using secure connection
I'm using the following code to create an email account and a email forward at the same time. I'm consfused as the email forward works every time (f2) and the email creation is only working roughly half the time (f1). I'm a PHP newbie and can't understand what could cause this. Any help is appreciated!
$f = fopen ("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddpop.html?email=$username&domain=$cpdomain&password=$password"a=0", "r");
fclose($f);
$f2 = fopen ("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddfwd.html?email=all&domain=$cpdomain&fwdemail=$email&fwdopt=fwd&submit=Add Forwarder", "r");
fclose($f2);
Yahoo is closing down Yahoo Mail Classic so I'm having to implement my own email. I currently use JustHost. I've made an effort to make the variables as easy to understand. If you don't understand what they mean then FIRST contact your host because (presuming you get a competent tech on the line) they'll understand what you'll need.
<?php
//exampledot.com for domain
$cpuser = 'exampled';////////////e.g. exampled, your cPanel main domain usually
$cppass = 'CPANEL-PASSWORD';/////Your cPanel password.
$cpdomain = 'exampledot.com';////The cPanel domain
$cpskin = 'justhost';////////////listed on cPanel as 'theme'
$emailname = 'john1';/////////////The username, e.g. john1#exampledot.com
$emaildomain = 'exampledot.com';////The domain name in email, #exampledot.com
$emailpass = 'EMAIL_PASSWORD';////The password for the email account
$quota = '25';///////////////////Megabytes of space, 0 for unlimited
$homepage = file_get_contents("https://$cpuser:$cppass#$cpdomain:2083/frontend/$cpskin/mail/doaddpop.html?email=$emailname&domain=$emaildomain&password=$emailpass"a=$quota");
echo $homepage;
?>
I used just that code and then checked cPanel and the email account was created.
So your URL does work, it was just that file_get_contents function is what you want to use.
with fopen
$fopen ("http://$cp_user:$cp_pass#$cp_domain:2082/frontend/$cp_skin/mail/doaddpop.html?email=$user&domain=$e_domain&password=$e_pass"a=$e_quota", "r");
for full plugin..
1.http://tobbynews.com/create-e-mail-account-in-c-panel-using-php.html
2.http://forums.cpanel.net/f42/xmlapi-php-class-111897.html
you can ask for support in cpanel's support for assistance..