1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Add Email Accounts

Discussion in 'E-mail Discussions' started by xMichio, May 12, 2004.

  1. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Hello, Anyone know is it possible to write a CGI or PHP script to tell cPanel to automatically add an email account and certain amount of quota to it?:confused:
     
  2. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Search Function :confused: bit lost on what you mean, sorry:rolleyes:
     
  3. challii

    challii Member

    Joined:
    Feb 3, 2004
    Messages:
    99
    Likes Received:
    0
    Trophy Points:
    6
    search the forums and search google!
     
  4. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    I've looked to find where I origionally found a portion of this and cannot. So the real author needs the credit.

    Code:
    <?php
        /*
        Create POP email accounts
        Works for me when others failed.
        */
        //include('header.php');
         
        // Domain Logon Details
        $username = "cpanellogin";
        $password = "cpanelpassword";
         
        // Domain details
        $domain = "domainname.com";
        $theme = "x";//eg "fantastico_bluelagoon";
         
        // Parameters to parse
        $eDomain = "domainame.com";
        $eQuota = "5"; // eg"10";
         
        if (isset($delpop)) {
            print "Account deleted : ".$popuser."@".$eDomain;
             
            $postfields = "email=$popuser&domain=$eDomain";
            $url = "http://$username:$password@$domain:2082/frontend/$theme/mail/realdelpop.html?$postfields";
            //print "<hr>";
            //print $url;
            // initialise Curl
            $popPost = curl_init();
            curl_setopt($popPost, CURLOPT_URL, $url);
            // Set Curl Option: Username:Password
            curl_setopt($popPost, CURLOPT_POST, 1);
            // Set Curl Option: Collect result from script
            curl_setopt($popPost, CURLOPT_RETURNTRANSFER, 1);
            // Set Curl Option: Set timeout to 15 seconds
            curl_setopt($popPost, CURLOPT_TIMEOUT, 15);
            // Set Curl Option: Post data
            //curl_setopt($popPost, CURLOPT_POSTFIELDS, $postfields);
            // Execute Request, and store result in $tb_post
            $popPost_result = curl_exec ($popPost);
            // Close Curl
            curl_close ($popPost);
            $start = strpos($popPost_result, 'Account');
            $end = strpos($popPost_result, 'Go');
            $subset = substr($popPost_result, $start, $end+8-$start);
            print $substr;
        }
         
        if (isset($eEmail)) {
            $ePassword = $password2;
            // Put post fields variable together
            $postfields = "email=$eEmail&domain=$eDomain&password=$ePassword&quota=$eQuota";
            // initialise Curl
            $popPost = curl_init();
            // Set Curl Option: URL
            $url = "http://$username:$password@$domain:2082/frontend/$theme/mail/doaddpop.html?$postfields";
            curl_setopt($popPost, CURLOPT_URL, $url);
            // Set Curl Option: Username:Password
            curl_setopt($popPost, CURLOPT_POST, 1);
            // Set Curl Option: Collect result from script
            curl_setopt($popPost, CURLOPT_RETURNTRANSFER, 1);
            // Set Curl Option: Set timeout to 15 seconds
            curl_setopt($popPost, CURLOPT_TIMEOUT, 15);
            // Set Curl Option: Post data
            //curl_setopt($popPost, CURLOPT_POSTFIELDS, $postfields);
            // Execute Request, and store result in $tb_post
            $popPost_result = curl_exec ($popPost);
            // Close Curl
            curl_close ($popPost);
             
            //output results
            $start = strpos($popPost_result, '<b>Account');
            $end = strpos($popPost_result, 'created.');
            $subset = substr($popPost_result, $start, $end+8-$start);
            $subset = str_replace('login ', "login<br>", $subset); //for neatness
            //$subset=str_replace("<!",'<-',$subset); //see the comments
            if (preg_match ('/Sorry/i', "$subset")) {
                print "<br><b>&nbsp;&nbsp;&nbsp;Sorry that account already exists.</b><br><br><br><br><br><br><br>";
                //print ($subset);
            } elseif(preg_match ('/You must specify/i', "$subset")) {
                print "<br><b>&nbsp;&nbsp;&nbsp;You must specify a password.</b><br><br><br><br><br><br><br>";
            } else {
                print ($subset);
                print "<br><br>You may now use <b>mail.$domain</b> as your POP3 setting in your mail client or access <b>WebMail</b> by selecting <a href=http://$domain/webmail>Here</a>.
                    <center>
                    <br><a href=javascript:history.go(-1)>Go Back</a>
                    </center>";
            }
        } else {
        ?>
    
        <form name="emailform" method="post" action="anew.php">
          <table border="0" cellspacing="1" align=center cellpadding="0">
            <tr> 
              <td>Prefered Email Address:</td>
              <td colspan="2"><input size=10 value="" name="eEmail" type="text">
            @<?= $domain ?></td>
            </tr>
            <tr> 
              <td>Password:</td>
              <td colspan="2"><input size=10 name="password1" value="" type="password"></td>
            </tr>
            <tr> 
              <td>Retype Password:</td>
              <td colspan="2"><input size=10 name="password2" value="" type="password"></td>
            </tr>
            <tr> 
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr> 
              <td>&nbsp;</td>
              <td width="344"> <div align="center"> 
                  <input name="signupbtn" type="button" id="signupbtn" value="Signup" onClick="validateform()">
                </div></td>
              <td width="163">&nbsp;</td>
            </tr>
          </table>
          <script language="JavaScript1.2">
        
        
        function validateform() {
            if (checkEmailAddress(document.emailform.eEmail)) {
                if(document.emailform.password1.value == document.emailform.password2.value) {
                    document.emailform.submit();
                }
                else 
                {
                    alert("The passwords you typed do not appear to match");
                }
            }
        }
        
        function checkEmailAddress(field) {
        var good;
        //var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
        var goodEmail = field.value;
        
        if(goodEmail != "") {
        //if (goodEmail){
           good = true
        } else {
           alert('Please enter a valid e-mail address.')
           field.focus()
           field.select()
           good = false
           }
           return good;
        }
        
        
        </script>
        </form>
        <? }
    //include('footer.php');
    ?>
    
    You need to look closely, Also have a function for delete but this form just adds.
     
  5. AlphaWebspace

    AlphaWebspace Member

    Joined:
    May 1, 2004
    Messages:
    136
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    United Kindom
    Umm cool thats what i needed but i cant get that to work can you help me please?
     
  6. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    I think i see kinda.. i think that code is 2 web pages, 1 for the php engine and 1 for the html form but i cant seem to get it to work :S
     
  7. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    You sure you are running Curl on your server?

    This is a single file. name it anew.php then make the changes in the config area. (this could be split out to a config file but for simplisity I left it in). If you name the file something else you need to edit the FORM tag in the html area.

    access the file via your web browser. the HTML portion calls the php portion.

    Edit this area near the top
    // Domain Logon Details
    $username = "cpanellogin";
    $password = "cpanelpassword";

    // Domain details
    $domain = "domainname.com";
    $theme = "x";//eg "fantastico_bluelagoon";

    // Parameters to parse
    $eDomain = "domainame.com";
    $eQuota = "5"; // eg"10";
     
  8. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    That is probaly why it didnt work, i dont have curl were can i get it?
     
  9. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    you can rebuild apache using /scripts/easyapache then select the option for CURL
     
  10. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Sorry to be a bother but I cant find this option when I rebuild it:S
     
  11. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    ok maybe this is easier.

    From your WHM you select Software->Update Apache.

    Now, there are lots of options here. if you are not sure I would suggest getting some help.
     
  12. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    TY :D I got it working, very much thanks
     
  13. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    NP, glad I could help
     
  14. xMichio

    xMichio New Member

    Joined:
    May 4, 2004
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    1
    Again, just out of curiosity, you wouldnt also have the script for email forwarders?:rolleyes:
     
  15. AlphaWebspace

    AlphaWebspace Member

    Joined:
    May 1, 2004
    Messages:
    136
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    United Kindom
    umm how do you mean email fowarders??? I have a script sort of if i think your on what im on about
     
  16. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    I did not before, but with modifications to the create email this one will work.
    Code:
    <?php
        /*
        Create Forward email accounts
        Works for me when others failed.
        */
        //include('header.php');
         
        // Domain Logon Details
        $username = "cpanellogin";
        $password = "cpanelpass";
         
        // Domain details
        $domain = "domainname.com";
        $theme = "x";//eg "fantastico_bluelagoon";
         
        // Parameters to parse
         
        if (isset($eEmail)) {
            // Put post fields variable together
            $postfields = "email=$eEmail&domain=$domain&forward=$forward";
            // initialise Curl
            $popPost = curl_init();
            // Set Curl Option: URL
            $url = "http://$username:$password@$domain:2082/frontend/$theme/mail/doaddfwd.html?$postfields";
            curl_setopt($popPost, CURLOPT_URL, $url);
            // Set Curl Option: Username:Password
            curl_setopt($popPost, CURLOPT_POST, 1);
            // Set Curl Option: Collect result from script
            curl_setopt($popPost, CURLOPT_RETURNTRANSFER, 1);
            // Set Curl Option: Set timeout to 15 seconds
            curl_setopt($popPost, CURLOPT_TIMEOUT, 15);
            // Set Curl Option: Post data
            //curl_setopt($popPost, CURLOPT_POSTFIELDS, $postfields);
            // Execute Request, and store result in $tb_post
            $popPost_result = curl_exec ($popPost);
            // Close Curl
            curl_close ($popPost);
             
            //output results
            $start = strpos($popPost_result, 'Add a new');
            $end = strpos($popPost_result, '<center>');
            $subset = substr($popPost_result, $start, $end-$start);
                print ($subset);
            exit;
            }
        ?>
    <html><head></head>
    <body>
        <form name="emailform" method="post" action="aforw.php">
          <table border="1" cellspacing="1" align=center cellpadding="0">
            <tr> 
              <td>Prefered Email Address:</td>
              <td><input size=10 value="" name="eEmail" type="text">
            @<?= $domain ?></td>
    <td> >>> </td>
              <td>Forward:</td>
              <td><input size=20 name="forward" value="" type="text"></td>
            </tr>
            <tr> 
              <td colspan="5" align="center"> 
                  <input name="signupbtn" type="submit" id="signupbtn" value="Submit">
              </td>
            </tr>
          </table>
        </form>
    </body>
    </html>
    
    
     
    #16 asmithjr, May 17, 2004
    Last edited: May 17, 2004
  17. jasonaud

    jasonaud New Member

    Joined:
    May 16, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    Would this process also work for doing subdomains. I want to make subdomains on the fly for a project we are working on and this is the first real thing i have found that looks like it might work.
     
  18. asmithjr

    asmithjr Member

    Joined:
    Jun 13, 2003
    Messages:
    406
    Likes Received:
    0
    Trophy Points:
    16
    Yes, take a look into the code. It could be modified.

    Let see you need doadddomain.html and you need rootdmain (maybe a hidden field) and domain as a input txt field.

    Code:
    <form action="doadddomain.html">
    <input type="text" name="domain">.<input type=hidden name=rootdomain>
    <input type="submit" value="Add">
    </form>
    

    this should get you started
     
    #18 asmithjr, May 17, 2004
    Last edited: May 17, 2004
  19. jasonaud

    jasonaud New Member

    Joined:
    May 16, 2004
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    thanks for the reply. i might have found it in another post but not sure yet. Yours just looked like the best. What we have to do is write a php script so when someone signs up and gives a list of words it will make the subdomains for us. We are custom writing the whole process but are hung up on this part. We tryed to enter it like from a form but then it was asking us for the username and password box like in a windows login box. So i saw your code and was hoping to make the subdomains was done like the way you showed to do the email addresses. If this is the case then i might have it but not sure yet. If ther eis any advise or code you know od that will help with this it is appriciated.

    Thank You
     
  20. AlphaWebspace

    AlphaWebspace Member

    Joined:
    May 1, 2004
    Messages:
    136
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    United Kindom
    I can not get the add an pop email account thingy to work can someone please help me!!!!
     

Share This Page