Need help with using API in PHP to add/remove email addresses to a Cpanel Account...
Hey guys,
I'm sure there has to be a few of you guys here who are going to say "That's easy..." but for someone who's not exactly a "coder/developer" - it may be for you!
I've got a service organization that I'm building a website for, and want to be able to allow members to sign-up and receive email addresses on the organizations domain - without ME having to go in and manually set them up inside CPanel.
Just something simple that would allow the members to 1) Check to see if the email address name is available, 2) set the email address and password, 3) click submit and viola - the email is setup. (and before anyone goes into the whole form security to keep bots off it, we've got covered already inside the CMS system that will have this form as part of its members area).
I'm more of an ADMIN than a coder... I can hack code to pieces and make it work, but when it comes creating new code from scratch forget it - I'm toast...
So if anyone has some examples, or can point me in the right direction - I'd love to hear it! And anyone willing to volunteer to help write some stuff, by all means! I BARTER... LOL
Robert J. Hantson
380 Mercury
-
Hello :) Our documentation website is a good place to start: [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/]cPanel & WHM's SDK You will find information on using our API for functions like creating email accounts. Note that if you need to have the script developed for you, the following is a list of development services on our application catalog: cPanel Application Catalog - Development Services Thank you. 0 -
To further narrow the scope, you might find use out of this API call: [url=http://docs.cpanel.net/twiki/bin/view/SoftwareDevelopmentKit/CallingAPIFunctions]cPanel XML and JSON APIs You'd basically use that to call the API2 functions that manage Email: [url=http://docs.cpanel.net/twiki/bin/view/ApiDocs/Api2/ApiEmail]Email Module Documentation 0 -
If you're not too keen on coding form scratch, check out the PHP client class for the cPanel API: set_debug(1); print $xmlapi->api2_query($user, "Email", "listpopswithdisk" ); ?>
Then you'll want to use json_decode() to pull the JSON into a PHP object and then loop through the results and print them out for people to see. You can copy the format of the email screen in cPanel for a basis for your UI. Your form should POST to a page that calls this to create a new email:password_auth($user,$pass); $xmlapi->set_port(2083); $xmlapi->set_output("json"); $email = $_POST["email">; $pass = $_POST["pass">; $params = array( 'domain' => '', #domain to add the email to 'email' => $email, #part of email before @ symbol 'password' => $pass, #hopefully a strong, randomly generated password 'quota' => 1000 #size in MB to allow the account to use ); $xmlapi->set_debug(1); print $xmlapi->api2_query($user, "Email", "addpop", $params ); ?>0
Please sign in to leave a comment.
Comments
3 comments