Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Using cPanel API for creating email account and forwarders in your own PHP scripts

  1. #1
    David I is offline Newbie
    Join Date
    Jun 2010
    Posts
    1,242

    Default Using cPanel API for creating email account and forwarders in your own PHP scripts

    Recently one of our clients asked: "Can I create email account within a php script?" Taking in consideration high possibilities of cPanel API we have decided to search for related requests on the Internet and have found out that many people are interested in this question.

    What is this needed for? For example, we have an awesome domain and you want to become a mail service provider, but creating mailboxes manually is not going to work. You can create addon domains, redirects and other things in the same way.

    We need following for the script:

    1. Request form (file index.php can be found in the attachments).
    2. cPanel XML API Client Class (file xmlapi.php can be found in the attachments).

    Let's check script of the form in detail:

    PHP Code:
    $ip "127.0.0.1";                // should be server IP address or 127.0.0.1 if local server
    $account "username";            // cPanel user account name
    $passwd ="password";            // cPanel user password
    $port =2083;                    // cpanel secure authentication port
    $email_domain 'domain.com';   // email domain (usually same as cPanel domain)
    $email_quota 50;                // default amount of space in megabytes 
    Creating XMLAPI request:


    PHP Code:

    $xmlapi 
    = new xmlapi($ip);

    //set port number. cpanel client class allow you to access WHM as well using WHM port.
    $xmlapi->set_port($port);                        

    // authorization with password. Not as secure as hash.
    $xmlapi->password_auth($account$passwd);   

    // cpanel email addpop function Parameters
    $call = array(domain=>$email_domainemail=>$email_user,password=>$email_passquota=>$email_quota);

    // cpanel email fwdopt function Parameters
    $call_f  = array(domain=>$email_domainemail=>$email_user,
    fwdopt=>"fwd"fwdemail=>$dest_email);

    //output to error file  set to 1 to see
    $xmlapi->set_debug(0);      
    error_log.

    // making call to cpanel api
    $result $xmlapi->api2_query($account"Email""addpop"
    $call);

    //create a forward
    $result_forward $xmlapi->api2_query($account"Email""addforward",
    $call_f); 
    And of course creating HTML form:

    HTML Code:
    <html>
    <head>
    <title>cPanel Email Account Creator</title>
    </head>
    
    <body>
    <?php echo '<div style="color:red">'.$msg.'</div>'; ?>
    
    <h1>cPanel Email Account Creator</h1>
    
    <form name="frmEmail" method="post">
    <table width="400" border="0">
        <tr>
            <td>Username:</td>
            <td><input name="user" size="20" type="text"/></td>
        </tr>    
        <tr>
            <td>Password:</td>
            <td><input name="pass" size="20" type="password"/></td>
        </tr>
        <tr>
            <td>Verify Password:</td>
            <td><input name="vpass" size="20"type="password" /></td>
        </tr>
        <tr>
            <td>Forwarde:</td>
            <td><input name="forward" size="20" type="text"/></td>
        </tr>
        <tr>
            <td colspan="2" align="center"><hr /><input name="submit" type="submit" value="Create Email" /></td>
        </tr>
    </table>
    </form>
    </body>
    </html>
    Related links:

    Creating multiple email account in cPanel with PHP and XMLAPI | Home Based Coder | Filipino Web Designer + Web Developer
    Create Email Account using API
    XMLAPI php class
    Auto create email with PHP
    cPanel XML and JSON APIs
    xpl-api and cPanel APIs via PHP
    Attached Files Attached Files
    Last edited by Matt; 07-13-2011 at 04:06 PM.

  2. #2
    Alberto Moreno is offline Almost no longer a newbie!
    Join Date
    Jul 2011
    Posts
    3

    Default Email Create from fron end

    Hello Matt

    Since I already have an index.php at public_html I am not sure about what to do about this file...

    Should I create a new folder for instance (email_create), and then upload these three files in it? (xmlapi.php, index.php email_create.html)

    Thanks
    Alberto
    regidordigital.com

  3. #3
    sergey is offline Master Glow Jedi
    Join Date
    Aug 2005
    Posts
    472

    Default

    You can rename the index.php to something else if you want to leave the files in public_html/ directory or you can place the files to a separate folder.

    Please note that the entire code is in one file index.php. If you want the form to be a separate file then it needs to be recoded a bit.

  4. #4
    Pratima is offline Newbie
    Join Date
    Jul 2011
    Posts
    1

    Default Videos explaining design patterns.

    I am looking for good quality videos explaining design patterns. Can anyone recommend videos I can download and view on my PC. I am willing to pay for the videos.

  5. #5
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,219

    Default

    You should probably start your own thread if you are looking for something specific.
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  6. #6
    Alberto Moreno is offline Almost no longer a newbie!
    Join Date
    Jul 2011
    Posts
    3

    Default

    hhh

  7. #7
    Alberto Moreno is offline Almost no longer a newbie!
    Join Date
    Jul 2011
    Posts
    3

    Default

    Hello

    I have created the form at

    http://regidordigital.com/email_crea...il_create.html

    But there must be something I am not doing properly...

    ............
    Where it says I have put down muy cpanel username
    and where it says password, the password...

    where it says domain.com I have written regidordigital.com

    I have protected the directory. I send you details to our private forum....

    What could be wrong??

    Thx
    Alberto

  8. #8
    Matt's Avatar
    Matt is offline GlowHost Administrator
    Join Date
    Jan 2005
    Location
    Behind your monitor
    Posts
    6,219

    Default

    Is there some error message on screen or in the error_log ?
    Send your friends and site visitors to GlowHost and get $125 plus bonus!
    GlowHost Affiliate Program | Read our Blog | Follow us on X |

  9. #9
    jcrimmel is offline Newbie
    Join Date
    Sep 2013
    Posts
    2

    Default Incorporate change password API2 script?

    I everyone. I know how old this thread is so I am not entirely expecting a reply.

    I am very new to Cpanel scripts and was able to set this up with no problems at all. I am using this to allow a client to create email address for themselves and their employees without having to take the extra step of requesting it through me. (I don't want to grant them direct Cpanel access)


    I have found the Cpanel API2 script for changing passwords
    Code:
    $xmlapi = new xmlapi("Primary CPANEL domain"); 
    $xmlapi->password_auth("username",$root_pass); 
    $account = "Cpanel username"; 
    $xmlapi->api2_query($account, "Email", "passwdpop", array( 'domain' => "domain name", 'email' => "user name", 'password' => "new password") ); 
    
    and I am wondering if there would be anyway to incorporate this into the files posted in this thread. I would love to give my clients the option to change the email password if they needed to. But as I said before I am literally just learning about Cpanel APIs (12 hours now and counting!) so I'm not really sure how one would go about implementing this.

    Anyone gracious enough to help out a very very green rookie?


    Thanks in advance.
    Jason

  10. #10
    Alexander's Avatar
    Alexander is offline Technical Analyst
    Join Date
    Jul 2007
    Posts
    1,876

    Default

    Well, maybe I missed something, but they can change passwords for their email accounts in Webmail. There is an option for it on the very first page when accessing Webmail. Thus, API is not needed.

Page 1 of 2 12 LastLast

LinkBacks (?)

  1. 08-03-2012, 08:09 AM

Similar Threads

  1. default timezone
    By Scott in forum Programming Talk
    Replies: 14
    Last Post: 03-24-2008, 07:48 PM
  2. Single Account, Multiple Domains to WHM Account
    By rickpugh in forum WHM, Resellers, VPS and Dedicated Hosting Topics
    Replies: 3
    Last Post: 08-15-2005, 11:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14