Web Hosting Talk







View Full Version : Automatically create just an email address in Cpanel


suiso
03-27-2004, 03:59 PM
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?

4Hosted
03-27-2004, 04:34 PM
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

markjut
03-27-2004, 04:48 PM
I use Cpanel/WHM and I don't believe it's possible right now :(

suiso
03-27-2004, 05:04 PM
I did not think so either, but I thought I would ask.

reviewum.com
03-27-2004, 06:12 PM
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!

danyprundus
03-27-2004, 08:28 PM
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

suiso
03-27-2004, 09:03 PM
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?

speeed
03-28-2004, 03:04 AM
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.

Xcel
03-28-2004, 04:29 AM
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.

suiso
03-28-2004, 04:38 AM
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:

<?
if ($submit){
$host = "domainName minus the www.";
$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($poststring, 0, -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($fp, 4096);
}


//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">
<? } ?>

danyprundus
03-28-2004, 10:49 AM
Hehe, yes, something like that. Solutions aren't always complicated. Anyway I'm still interested in any projects you might have:)

reviewum.com
03-28-2004, 07:49 PM
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"!!!

suiso
03-28-2004, 08:42 PM
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:

$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:

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 //:

while(!feof($fp)) {
echo fgets($fp, 4096);
}


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.

reviewum.com
03-28-2004, 08:56 PM
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!

suiso
03-28-2004, 09:23 PM
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......

Quickcess
03-29-2004, 08:57 AM
Check this doc. Haven't tried it myself, but seems to be ok to work :)
omidsoft.com/tutorial/create_mailbox_cpanel

PartieHonteuse
05-25-2004, 08:50 AM
Suiso, i'm having some trouble with your code.. Although, you say to remove this line..

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 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™

naguib2000
05-26-2004, 05:27 AM
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)

jameso
05-26-2004, 05:39 AM
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

naguib2000
05-26-2004, 05:59 AM
you can use something like this in your code

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

it is the easiest way

PartieHonteuse
05-27-2004, 04:11 AM
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™

joekushner
05-27-2004, 06:31 AM
cut and dry way....


//////////////////////////////////////////////////////
// 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, $err2, 30);
socket_set_timeout($socket, 30);
$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 :)

PartieHonteuse
05-27-2004, 07:19 AM
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¢À

joekushner
05-27-2004, 09:03 AM
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 :)

PartieHonteuse
05-30-2004, 09:41 AM
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™

barfly
07-15-2004, 11:28 PM
i've tried a few of these scripts with no luck,
just wondering if anyone has come up with something a little simpler for a novice like me?

barfly
07-16-2004, 12:20 AM
i found one that worked for me!

search sourceforge dot com for cpanemail

barfly
07-16-2004, 12:27 AM
i found one that worked for me!

search sourceforge dot com for cpanemail

SassyLuvs
07-21-2004, 06:58 PM
Hi everyone,
I was wondering if there was a way to do this for "Email Redirection" for CPanel?

Shaw Networks
07-22-2004, 03:07 AM
Great solution, I'll be adding this to a few sites; offering free webmail :)

princeshoko
05-21-2007, 11:39 PM
Found this, and it works expect i been having trouble recodeing this to a way id like so any help would be ok, (I know its old but its still works and am having a simple issue)

Trying to make the $hosts = "domain"; to where in the forum you can select a domain from a drop down list <select name=

So heres the question

How can i change this to where the selected domain in the forum is used as the $host = "DROPDOWN"

Thanks
Hope it makes sence what i want.