Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 18
  1. #1
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default Auto create email with PHP

    I have cpanel version 11 and i try to auto create email from PHP using this code

    <?php
    $cpuser = "cpanel_user_name";
    $cppass = "cpanel_password";
    $euser = "email_user_name";
    $epass = "email_password";
    $equota = "email_quota";
    $domain = "domian.com";
    $url = "http://".$cpuser.":".$cppass."@".$domain."2082/frontend/x3/mail/doaddpop.html?email=".$euser."&domain=".$domain."&password=".$epass."&quota=".$equota;
    if($cpanel = fopen($url, "r"))
    {
    echo "Success email creation.";
    fclose($cpanel);
    }
    else
    {
    echo "Failed email creation.";
    }
    ?>

    When I run this code I get the result "Success email creation." but when I login to cpanel I not found the new email in the list.

    What the wrong ?

  2. #2
    Registered User
    Join Date
    Jul 2008
    Posts
    4

    Default

    I have cPanel version 11.24.5 and I can confirm that I have almost exactly the same problem. I run my script, which returns this array:

    Code:
    array(3) {
      ["apiversion"]=>
      string(1) "2"
      ["func"]=>
      string(6) "addpop"
      ["module"]=>
      string(5) "Email"
    but when I login on cpanel, the email address isn't shown...this is driving me mad...

    I run the instruction with an api2 query like this:
    PHP Code:
    $arr $xmlapi->api2_query($account"Email""addpop", array(domain=>$res['domain'], email=>$email1password=>$password1quota=>0) );
    var_dump($arr); 
    I know I'm authenticating correctly, because I can list bandwidth usage, etc. without any problems...

    This is an urgent problem and any help would be greatly appreciated.

  3. #3
    Member
    Join Date
    Apr 2005
    Posts
    12

    Default Same here

    Hi,

    I also use a script to create email and other stuff.
    All works fine exept the email part.

    Anyone got news from Cpanel ?

    Thanks
    Robert-Jan

  4. #4
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default addpop via XML-API

    Hi guys,

    Using the XMLAPI.php class, you should be about to add pop emails to an account like so:
    Code:
    $username = 'dave'; //cpanel username associated with our domain
    $newpopdata = array(
     'domain'=>'dave.com',
     'email'=>'mr_dave',
     'password'=>'my_s3cr3t_pop!passwd',
     'quota'=>0,
    );
    $result = $xmlapi->api2_query($username, "Email", "addpop", $newpopdata);
    This is the same as nelwa's code. The main difference is I'm quoting my array keys; not fatal, but depending it may affect your code.

    I know for certain that his works on 11.25.0. However, I will try on an 11.24.5 server later and will post my findings.

    Regards,
    -Dave
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  5. #5
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default api call to add pop

    Hi guys,

    Unfortunately, the documentation isn't crystal clear on api2 calls via URL. Short answer: not all api2 calls are supported in 11.24.5. All api1 calls are. Use an api1 like the following example for 11.24.5:
    Code:
    $account = "dave";
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    The actual url query string would look like:
    Code:
    https://10.1.5.162:2087/xml-api/cpanel?user=dave&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=addpop&cpanel_xmlapi_apiversion=1&arg-0=mr_dave&arg-1=my_s3cr3t_pop!passwd&arg-2=0&arg-3=dave.com
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  6. #6
    cPanel Staff cPanelMatt's Avatar
    Join Date
    Apr 2005
    Location
    Houston, TX
    Posts
    409

    Default

    More clarification:

    The API2 documentation was targetted @ 11.25.0. At the time we started developing it we decided that it was less of a time sync to target the release that would be coming out shortly.

    I apologize for the confusion.
    Matt Dees
    Integration Developer
    cPanel, Inc.
    cPanel Integration Blog

  7. #7
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    Hi guys,

    Unfortunately, the documentation isn't crystal clear on api2 calls via URL. Short answer: not all api2 calls are supported in 11.24.5. All api1 calls are. Use an api1 like the following example for 11.24.5:
    Code:
    $account = "dave";
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("root",$root_pass);
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    The actual url query string would look like:
    Code:
    https://10.1.5.162:2087/xml-api/cpanel?user=dave&cpanel_xmlapi_module=Email&cpanel_xmlapi_func=addpop&cpanel_xmlapi_apiversion=1&arg-0=mr_dave&arg-1=my_s3cr3t_pop!passwd&arg-2=0&arg-3=dave.com
    I think the previous code using with WHM account only but in my status I have only cpanel account.

  8. #8
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

    Code:
    $account = "dave";
    $account_pass = "d4v3sSecret!";
    
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  9. #9
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

    Code:
    $account = "dave";
    $account_pass = "d4v3sSecret!";
    
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    I get an error when I execute this code
    (HTTP 500 Internal Server Error)
    The website cannot display the page
    HTTP 500
    Most likely causes:
    •The website is under maintenance.
    •The website has a programming error.

    What you can try:
    Refresh the page.

    Go back to the previous page.

    More information

    This error (HTTP 500 Internal Server Error) means that the website you are visiting had a server problem which prevented the webpage from displaying.

    For more information about HTTP errors, see Help.

  10. #10
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

    Code:
    $account = "dave";
    $account_pass = "d4v3sSecret!";
    
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    cPanelDavidN what is $ip ? I what the value of $ip here ?
    Last edited by bwor; 06-13-2010 at 02:53 PM.

  11. #11
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    You can authenticate with your user credentials and as long as you're only requesting action for your account, it should succeed.

    Code:
    $account = "dave";
    $account_pass = "d4v3sSecret!";
    
    $email_user = "mr_dave";
    $email_password = "my_s3cr3t_pop!passwd";
    $email_domain = "dave.com";
    $email_quota = '0';
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth($account, $account_pass);  <-- USE USER ACCOUNT AUTH
    $xmlapi->set_output('xml');
    
    $result = $xmlapi->api1_query($account, "Email", "addpop", array($email_user, $email_password, $email_quota, $email_domain) );
    You can check the output of execution this code from this link
    2shared - download Error_01.jpg

  12. #12
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    $ip is a variable containing the IP address of the server. You could also use you domain name. You must populate this with your own information.

    The xmlapi object must have the address (IP or domain) to know where to send the requests.

    If you don't have the right web address, then I'd expected to see the 500 errors you're getting. Try putting in your domain name and see what you get.

    Regards,
    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  13. #13
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    $ip is a variable containing the IP address of the server. You could also use you domain name. You must populate this with your own information.

    The xmlapi object must have the address (IP or domain) to know where to send the requests.

    If you don't have the right web address, then I'd expected to see the 500 errors you're getting. Try putting in your domain name and see what you get.

    Regards,
    -DavidN
    I checked the error_log file and I get this result after execution your code
    PHP Code:
    [15-Jun-2010 15:52:59PHP Fatal error:  Class 'xmlapi' not found in /home/xxxx/public_html/yyyy/test/test.php on line 13 
    What is that meaning ?

  14. #14
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    525

    Default

    in your test.php, you need to include/require the xmlapi client class.
    Code:
    include('xmlapi.php');
    you'll need to download the class from here http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.5.tar.gz and extract it. Place "xmlapi.php" somewhere that's in you PHP include_path (or modify your include_path in test.php to include the directory where you placed "xmlapi.php").

    the download also includes examples of how to use the class.

    -DavidN
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  15. #15
    Member
    Join Date
    Jun 2008
    Posts
    17

    Default

    Quote Originally Posted by cPanelDavidN View Post
    in your test.php, you need to include/require the xmlapi client class.
    Code:
    include('xmlapi.php');
    you'll need to download the class from here http://sdk.cpanel.net/lib/xmlapi/php..._v1.0.5.tar.gz and extract it. Place "xmlapi.php" somewhere that's in you PHP include_path (or modify your include_path in test.php to include the directory where you placed "xmlapi.php").

    the download also includes examples of how to use the class.

    -DavidN
    Thanks alot and it's working now and I think you can close this thread.

Similar Threads & Tags
Similar threads

  1. Auto Create Account w/PHP
    By markfrompf in forum cPanel Developers
    Replies: 24
    Last Post: 01-26-2012, 08:39 AM
  2. Auto create new email account
    By cyndre2 in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 09-19-2008, 11:05 AM
  3. Auto-limiting outgoing email via localhost/PHP
    By brianoz in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 08-19-2006, 09:50 AM
  4. Email question - auto create
    By prixone in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 11-04-2005, 10:47 PM
  5. Use php to AUTO create a users account???
    By armega in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 07-13-2004, 01:01 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube