How to make new email accounts for cPanel user, from PHP script
Hello,
I need to add new email accounts to a cPanel user, from a PHP script called through Apache, like so:
http://example.com/add-email-account.php
I also need to add a forwarder for each new email account, from a PHP script called through Apache, like so:
http://example.com/add-email-forwarder.php
I thought LiveAPI would allow this, but apparently it doesn't.
Can you show me how to do this?
Thank you.
-
Hello :) You may find the PHP client class helpful: Thank you. 0 -
Hello, Thank you for the reference to the PHP client class. However, it doesn't appear to support addforward or delpop. For a remote application, I got addpop addforward and delpop to work by accessing the cPanel API-2 functions through the WHM API with hash authentication. 1) Note on addforward: addforward duplicates a pre-existing forward without warning, so if you call addforward twice on the same email account, your forwards file look like this (for example.com): # cat /etc/valiases/example.com user@example.com : user@gmail.com, user@gmail.com 2) Note on delpop: delpop takes many seconds to return, which causes the web server to timeout. The email account targeted by delpop for deletion may or may not be deleted, but either way you get no confirmation because the web server terminates the connection. 3) There is no delforward function. 4) What is the fastest way to determine whether or not a given email account already exists on the server? Thank you. 0 -
https://github.com/N1ghteyes/cpanel-UAPI-php-class There is an example for mysql databases in there, but it is the same principle. Set the scope to Email and then just call any UAPI functions like you would class methods. e.g. include "../cpaneluapi.class.php"; //include the class file $uapi = new cpanelUAPI('cPuser', 'cPpass', 'cPanel.example.com'); //instantiate the object $uapi->scope = 'Email'; //use the email module //create an email address $uapi->add_pop(array('email' => 'email@email.com', 'password' => 'password123', 'quota' => 0, 'domain' => 'email.com')); simple as that :). The class uses PHP magic functions inplace of methods, see: [url=http://php.net/manual/en/language.oop5.overloading.php#object.call]PHP: Overloading - Manual 0 -
I am using your cpanelUAPI class to create an email account. It works except that it seems that add_pop is being called twice. The email address is created, but I get the error message of 'The account test@example.com[/EMAIL] already exists!'. The following is my code. $uapi = new cpanelUAPI('user', 'password, 'server.com'); $uapi->scope = 'Email'; $data = $uapi->add_pop(array('email' => 'test@example.com[/EMAIL]', 'password' => 'mypwd', 'quota' => 0, 'domain' => 'example.com'));
Is this a known problem with the cpanelUAPI class? Thank you for any help.0 -
Hi Angela It is a known bug, theres a fix waiting to be pushed to git, but in the mean time, change line 99 from $content = $this->curl_exec_follow($ch); to $content = $this->curl_exec_follow($ch, 0); that should do it 0
Please sign in to leave a comment.
Comments
5 comments