Page 1 of 2 12 LastLast
Results 1 to 25 of 32
  1. #1
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37

    Automatically create just an email address in Cpanel

    After lurking for close to a month now I would like to say thank you for all that I have learned here. I recently upgraded hosts to a reseller with WHM/Cpanel.

    My question is how do I automatically create just an email address in Cpanel? I would like to have a form that my registered users fill out and an email would be automatically created in my domain. Is this even possible?

    I think I am pretty savvy when it comes to PHP so I thought a look through the cPanel Accounting PHP module API would help. This documentation is really lacking. It is called the cPanel Accounting PHP module, but it is really a WHM Accounting PHP module. I see the routines to create an account, but only in the WHM.

    I have looked at PHPCoin, and other to see if I could 'borrow' some code from them, but it looks like they all deal with WHM and not the domain specific Cpanel.

    Any ideas?

  2. #2
    this is not exactly possibly within Cpanel.

    The only thing you can do is Get some software like Socketmail or Hivemail.

    That type of software uses the "Catch all" email account and then distributes the email to the webmail client users.

    Sadly i dont think they use POP or IMAP

  3. #3
    Join Date
    Aug 2003
    Posts
    2,733
    I use Cpanel/WHM and I don't believe it's possible right now

  4. #4
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37
    I did not think so either, but I thought I would ask.

  5. #5
    Join Date
    Nov 2002
    Posts
    53
    Here is something I used for a project I did a few months ago:

    "Cpanelmail is a small script to let users create their own email accounts without you having to do a thing. "

    http://lucidstorm.com/scripts.php

    My programmer had to tweak it a bit to get it to work with our application, but it ended up giving him all the info he needed to see how to create email accounts outside of Cpanel.

    Good luck and report back if / when you find something!

  6. #6
    Well, it can be done As matter of fact I did this.The user fills in a form with desired username, password and the script creates and email for him using Cpanel.
    PM me if interested in this solution
    Thank you

  7. #7
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37
    danyprundus,

    I am interested in this if it is a free solution. Not sure I can afford much. I tried to PM you, but I get access denied. Oh well. Could you email me the detail or post a link here on the board?

  8. #8
    this is something i would like to have also if i can and its free. can't do much at this time for money. i don't want to signup for your other srevices becaus ei have my own already. sorry.

  9. #9
    Join Date
    May 2003
    Posts
    78
    WHM/Cpanel always creates a default email with login username and password.

    In fact I had the the opposite problem you do awhile back. I wanted to find out how to make Cpanel not create an email address. I was going to offer free hosting without email but couldn't find a way to stop it from creating an email.

    If you need it to create a specific email thats a different story.

  10. #10
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37
    After looking at Cpanel and how it passes URL I was able to Goggle up a thread at hosting-unlimited.net's forums. I tested the code and it works!!! Very simple, but I can put a MySQL database on the back end so I get no dups. Here is the code:
    PHP Code:
      <?
      
    if ($submit){
      
    $host "domainName minus the [url]www.[/url]";
      
    $port 2082;
      
    $path "/frontend/x2/mail/doaddpop.html"//or .dll, etc. for authnet, etc.
      
      // these lines are changed
      
    $cpaneluser "Cpanel Username";
      
    $cpanelpass "Cpanel Password";
      
    $authstr "$cpaneluser:$cpanelpass";
      
    //****************************
      
      // Setup the Auth String
      
    $pass base64_encode($authstr);
      
      
    //Setup an array of all the POST data
      
    $formdata = array ( "email" => $email"domain" => $host"password" => $password"quota" => $quota);
      
    //build the post string
        
    foreach($formdata AS $key => $val){
         
    $poststring .= urlencode($key) . "=" urlencode($val) . "&";
        }
      
    // strip off trailing ampersand
      
    $poststring substr($poststring0, -1);
      
      
    $fp fsockopen($host$port$errno$errstr$timeout 30);
      
      if(!
    $fp){
       
    //error tell us
       
    echo "$errstr ($errno)\n";
        
      }else{
      
        
    //send the server request
        
        
    fputs($fp"POST $path HTTP/1.1\r\n");
        
    fputs($fp"Host: $host\r\n");
        
    fputs($fp"Authorization: Basic $pass \r\n");
        
    fputs($fp"Content-type: application/x-www-form-urlencoded\r\n");
        
    fputs($fp"Content-length: ".strlen($poststring)."\r\n");
        
    fputs($fp"Connection: close\r\n\r\n");
        
    fputs($fp$poststring "\r\n\r\n");
      
      
    //*************************************
      // Remove this to stop it from displaying the output fron the CPanel
      //*************************************
        //loop through the response from the server
        
    while(!feof($fp)) {
         echo 
    fgets($fp4096);
        }
        
        
        
    //close fp - we are done with it
        
    fclose($fp);
      }
      print  
    "Email Account Created";
      }else{
      
    ?>
      <form method="post">
      Username:<input type="text" name="email"><br>
      Password:<input type="password" name="password"><br>
      Quota:<input type="text" name="quota">
      <input type="submit" name="submit" value="true">
      <? ?>

  11. #11
    Hehe, yes, something like that. Solutions aren't always complicated. Anyway I'm still interested in any projects you might have

  12. #12
    Join Date
    Nov 2002
    Posts
    53
    Well... I'll be! It actually worked... (had to change the "/frontend/x2/mail/doaddpop.html" to ""/frontend/bluelagoon/mail/doaddpop.html"

    Now, for those of us (me) that aren't programming inclined, how do I ensure that my cpanel pass, etc. aren't out there to be viewed? Also, the results page had a bunch of missing Cpanel images... any way to fix this?

    Thanks suiso! Not a bad post for a "newbie"!!!

  13. #13
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37
    Boy reviewum.com, you should talk

    The best way to ensure that your cpanel pass/account is secure is to move that to a config file outside your webroot and call it in the main script file like this:
    PHP Code:
      $host "domain.name"//your domain name
      
    $port 2082
      
    $path "/frontend/x2/mail/doaddpop.html"//change x2 to your theme. 
      
    $cpaneluser "Cpanel Username"
      
    $cpanelpass "Cpanel Password"
      
    $authstr "$cpaneluser:$cpanelpass"
    Name this file config.php and move it outside of your public_html folder.
    Now remove these lines from the main script and add:
    PHP Code:
    include("../config.php"); 
    You might need the full path to config.php for this to work. If you want to remove the Cpanel images and text comment out //:
    PHP Code:
        while(!feof($fp)) { 
         echo 
    fgets($fp4096); 
        } 
    Mind you that even if an account does exist on your server it will say 'Account Created'. This is just a sample of what can be done. I am working on a MySQL backend that now that will check the DB before it posts it to Cpanel.

  14. #14
    Join Date
    Nov 2002
    Posts
    53
    I'm surprised there aren't a million of these cpanel / email scripts already out there, not to mention one that uses a flat file or mysql DB to check if an account already exists, etc.

    suiso, keep up the great work! I'd love to see the final version!

  15. #15
    Join Date
    Mar 2004
    Location
    In The Tree Outside Your Bedroom Window
    Posts
    37
    You pointed me in the right dirction. Cpanelmail does just that, but they want money for it. After seeing how Cpanel passes the URL and how MySQL backend whould check for accounts, thanks to Cpanelmail, this just got the ball rolling.

    I would love to post a finished link to the code here IF I finish it, but I am no PHP guru. Right now content is king on my sites and not function. Til then......

  16. #16
    Check this doc. Haven't tried it myself, but seems to be ok to work
    omidsoft.com/tutorial/create_mailbox_cpanel

  17. Suiso, i'm having some trouble with your code.. Although, you say to remove this line..

    Code:
         while(!feof($fp)) {
    
         echo fgets($fp, 4096);
    
        }
    I thought I'd get rid of my cookies and delete the files from the server and upload the newest ones to no avail...also...how could I get rid of the IF statement at the top. I've sorta modified the code to have the mysql database and it's also part of phpbb. I know what it does but then your if/then statement won't work near the bottom and I have no idea how to modify it from there. What I would like it to do is once it gets to this line
    Code:
    print  "Email Account Created";
    I could actually include another file that prints out some stuff like "Congrats, you have a new email from..." etc.etc. Please help!

    Partie™

    Partie™

  18. #18
    Join Date
    May 2004
    Posts
    66
    Actually i made it with php in only 2 lines

    and i ve been 1 year using it without anybugs , we have a site where users can automatically creat their emails

    It seems we have some weak php developers around here !!

    If any body needs it , you can demand it .....(sure 4 free)

  19. #19
    Join Date
    Jun 2002
    Location
    Perth, Australia
    Posts
    85
    Has anyone tried a method similar to this to change a cpanel user's password?

    Also, it would be handy if we could update a cpanel user's contact email address too.

    I'm sure its possible using a script similar to suiso's - I might give it a try sometime.

    James

  20. #20
    Join Date
    May 2004
    Posts
    66
    you can use something like this in your code

    <?
    file("http://username:password@http://www.yoursite.com:2082/fronten....com&password=$password
    &amp;quota=20&submit=create&email=$username");
    ?>

    it is the easiest way

  21. This is why I hate asking for programming help. Most programmers won't help you unless you've been in their "clique" for years and when someone finally does ask for help they're ridiculed for asking. So, next time when a specific question is asked, how about not giving me an opinion and just giving me a solution or a pointer for my problem.


    Thanks.

    Partie™

  22. #22
    cut and dry way....

    PHP Code:
    //////////////////////////////////////////////////////
                // Create email address on the fly                  //
                //////////////////////////////////////////////////////
                
    $host "www.whatever.com";//your url
            
    $domain "whatever.info";//your domain without the www
                //Cpanel options:
                
    $cpaneluser "xxxx";//your cpanel username
                
    $cpanelpass "xxxx";//your cpanel password
                
    $cpaneltheme"x"//this is the word after frontend/ and the next / when you login to cpanel
                
    $spacequota=128;//how much space in k you want to give the user
                
                // move the above to a config.php file then call it below

                
                //include("../mailconfig.php");
                
                
                
    $socket fsockopen($host,2082$err1$err230);
                
    socket_set_timeout($socket30);
                
    $authstr "$cpaneluser:$cpanelpass";
                
    $pass base64_encode($authstr);                                                                       
                
    $in "GET /frontend/x/mail/doaddpop.html?email=$row[username]&domain=comain.com&password=$old_password&quota=1\r\n HTTP/1.0\r\nHost: $host\r\nConnection: Keep-Alive\r\nAuthorization: Basic $pass \r\n\r\n";
                            
                
                
    fputs($socket,$in);
                
                
    //test data////////
                
    $var1 fgets($socket);
                            if (
    substr_count($var1"200 OK") > 0)
                            {
                                    
    $var2 false;  
                                    while ( !
    $var2)
                                    {
                                        
    $var1=fgets($socket);
                                        if (
    $var1 == false)
                                          
    $var2 true;
                                    }
                                    
    //return $socket;
                            
    }
                            else if (
    strlen($var1) < 15)
                            {
                                    
    fclose($socket);
                                    
    //return -1;
                            
    }
                            else       
                            {
                                    
    fclose($socket);
                                    
    //return 0;
                                    
                            
    }
                
    fclose$socket );
            
    //////////////////////////////////////////////////////
                // end creating email address                       //
                ////////////////////////////////////////////////////// 
    should work.... I have this code in the signup area of a phpNuke site to auto generate an email address with the user name
    Joe
    www.DollarWebHosting.Biz
    |:| Shared |:| Reseller |:| Dedicated |:|

  23. Thanks a lot joe, I actually figured out my problem ON MY OWN...no thanks to naguib2000 but I do appreciate the code that you have posted. My problem was the person that posted the earlier code said to take out a line to stop it from displaying the output from cpanel, when i did that, it wouldn't work...so, I did some studying up on some of the different things he used and found all I had to do was delete the "echo" lmao, sad, but true...

    Partie¢À

  24. #24
    ya under the //test data comments is the delay waiting for the response from cpanel... a cpanel update not to long ago required this for the script to work. I had to find that the hard way too.

    your welcome for the code... i found it for free, and don't feel charging for it would be right... FYI it was buried in the cpanel forums about needed to wait for the cpanel response
    Joe
    www.DollarWebHosting.Biz
    |:| Shared |:| Reseller |:| Dedicated |:|

  25. Ok guys and dolls. Not too sure who would care to read what I'm about to say, but for those of you who use phpBB I've actually created a phpbb MOD out of the code Suiso provided. If you'd like to take a look @ it either reply here or send me a PM. As of this writing Version = 2.1.0

    Also, you can look at the initial release of my MOD at phpbbhacks.com
    Moderators of this forum...sorry if this isn't allowed, if it's not please delete/edit this post as needed.


    Thanks again to everyone that helped and posted the initial code!
    Partie™

Page 1 of 2 12 LastLast

Posting Permissions

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