ubanunewby
May 5th, 2009, 02:48 PM
I wanted to get a method to allow users to automaticly register their own email addresses. I could not find an existing one so I put together this one. It is working successfully. I installed my system using the EHCP 2.7.
adduser.php
<?php
/* Squirrelmail self register user account.
* Written by Jonathan Fraser (jon@unstoppables.org)for EHCP generated Squirrelmail.
*
* These scrips update a MYSQL database that stores the usernames and passwords. addemail.php calls adduser.php,
* checks for a password and an existing username, and adds the entered name into the table. Welcome email is sent
* and a confirmation email is sent to the administrator (or any existing account).
*
* CAPTCHA found at http://www.phpcaptcha.org by Drew Phillips <drew@drew-phillips.com> was used
* to prevent automated signup. The initial page (addemail.php)
* reuses Captcha's example_form.php adding my form instead of confirmation. securimage.php,
* securimage_show.php and elephant.tff are the required files.
*/
//setup variables.
$user = 'user'; //Enter your mysql username (limited user)
$pw = 'password'; //Enter your mysql password
$db = 'ehcp'; //Enter your database containing email users (for ehcp this does not need to be changed)
$domainname='domain.org'; //Enter your domain name
$quota='10'; //quota
$mailusername= $_POST['mailusername']; //Info from post form
$password= $_POST['password'];
if($password == null) { //check password
echo '<h3>Please enter a password</h3>';
echo '<a href=http://www.domain.org/addemail.php>Go back</a>'; //Enter your domain name here
exit;
}
$mysql_access = mysql_connect("localhost", $user, $pw); //connect to mysql database
mysql_select_db($db, $mysql_access);
$query = "SELECT mailusername FROM emailusers WHERE mailusername='$mailusername' "; //check database
$result = mysql_query($query, $mysql_access);
if(mysql_num_rows($result)) {
print("<H2><FONT color=red> $mailusername already exists in database.</FONT></H2>");
echo '<a href=http://www.domain.org/addemail.php>Go back</a>'; //Enter your domain name here
exit;
}else{
$query = "INSERT INTO emailusers (panelusername,domainname,mailusername,email,passw ord,quota)"; //enter data into database
$query .= "VALUES('admin','$domainname','$mailusername','$mai lusername@$domainname','".$password."','".($quota*1000000)."')";
mysql_query($query, $mysql_access);
$to = "$mailusername@$domainname"; //send email to new user and to administrator
$subject = "Welcome";
$message = "Welcome to $domainname email.";
$from = "admin@$domainname";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
$tome="admin@$domainname";
$subj="New user created";
$messg="$mailusername@$domainname";
mail($tome,$subj,$messg,$headers);
print("<H3><FONT color=blue>Successfully added your email!</FONT></H3> <BR> $mailusername@$domainame<BR> Password: $password");
echo '<br><a href=http://www.domain.org/vhosts/ehcp/webmail>Login to webmail</a>'; //Enter your domain name here
}
?>
addemail.php
<?php session_start();
?>
<!--
Squirrelmail self register user account.
* Written by Jonathan Fraser (jon@unstoppables.org)for EHCP generated Squirrelmail.
*
* These scrips update a MYSQL database that stores the usernames and passwords. addemail.php calls adduser.php,
* checks for a password and an existing username, and adds the entered name into the table. Welcome email is sent
* and a confirmation email is sent to the administrator (or any existing account).
*
* CAPTCHA found at http://www.phpcaptcha.org by Drew Phillips <drew@drew-phillips.com> was used
* to prevent automated signup. The initial page (addemail.php)
* reuses Captcha's example_form.php adding my form instead of confirmation. securimage.php,
* securimage_show.php and elephant.tff are the required files. -->
<html>
<head>
<title>Add Email Account</title>
</head>
<body><center>
<?php
if (empty($_POST)) { ?>
<form method="POST">
<!-- pass a session id to the query string of the script to prevent ie caching -->
Enter text in picture and click Submit.<BR>
<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
<input type="text" name="code" /><br />
<input type="submit" value="Submit" />
</form>
<?php
} else { //form is posted
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == true) {
$domainname='domain.org'; //Enter your domain name here
echo "<HTML>",
"<title>Add Email User - '$domainname' </title>",
"<body><br><br><div id='divMain' align='center'>",
"Adding domain/email user for domain: '$domainname' <br>",
"(do not write @domainname)<br>",
"<form method=post action=adduser.php> ",
"<table><tr><td>emailusername </td><td> ",
"<input type=text name=mailusername value=''>@'$domainname'",
"</td></tr><tr><td>password </td><td> ",
"<input type='password' name=password value=''></td></tr><tr><td>",
"<input type=hidden action=adduser.php></td></tr>",
"</table><input type=submit value='Submit'>",
"</form></div></body></html>";
} else {
echo "<center>Sorry, the code you entered was invalid. <a href=http://www.domain.org/addemail.php>to try again.</a></center>"; //Enter your domain name here
}
}
?>
</center>
</body>
</html>
adduser.php
<?php
/* Squirrelmail self register user account.
* Written by Jonathan Fraser (jon@unstoppables.org)for EHCP generated Squirrelmail.
*
* These scrips update a MYSQL database that stores the usernames and passwords. addemail.php calls adduser.php,
* checks for a password and an existing username, and adds the entered name into the table. Welcome email is sent
* and a confirmation email is sent to the administrator (or any existing account).
*
* CAPTCHA found at http://www.phpcaptcha.org by Drew Phillips <drew@drew-phillips.com> was used
* to prevent automated signup. The initial page (addemail.php)
* reuses Captcha's example_form.php adding my form instead of confirmation. securimage.php,
* securimage_show.php and elephant.tff are the required files.
*/
//setup variables.
$user = 'user'; //Enter your mysql username (limited user)
$pw = 'password'; //Enter your mysql password
$db = 'ehcp'; //Enter your database containing email users (for ehcp this does not need to be changed)
$domainname='domain.org'; //Enter your domain name
$quota='10'; //quota
$mailusername= $_POST['mailusername']; //Info from post form
$password= $_POST['password'];
if($password == null) { //check password
echo '<h3>Please enter a password</h3>';
echo '<a href=http://www.domain.org/addemail.php>Go back</a>'; //Enter your domain name here
exit;
}
$mysql_access = mysql_connect("localhost", $user, $pw); //connect to mysql database
mysql_select_db($db, $mysql_access);
$query = "SELECT mailusername FROM emailusers WHERE mailusername='$mailusername' "; //check database
$result = mysql_query($query, $mysql_access);
if(mysql_num_rows($result)) {
print("<H2><FONT color=red> $mailusername already exists in database.</FONT></H2>");
echo '<a href=http://www.domain.org/addemail.php>Go back</a>'; //Enter your domain name here
exit;
}else{
$query = "INSERT INTO emailusers (panelusername,domainname,mailusername,email,passw ord,quota)"; //enter data into database
$query .= "VALUES('admin','$domainname','$mailusername','$mai lusername@$domainname','".$password."','".($quota*1000000)."')";
mysql_query($query, $mysql_access);
$to = "$mailusername@$domainname"; //send email to new user and to administrator
$subject = "Welcome";
$message = "Welcome to $domainname email.";
$from = "admin@$domainname";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
$tome="admin@$domainname";
$subj="New user created";
$messg="$mailusername@$domainname";
mail($tome,$subj,$messg,$headers);
print("<H3><FONT color=blue>Successfully added your email!</FONT></H3> <BR> $mailusername@$domainame<BR> Password: $password");
echo '<br><a href=http://www.domain.org/vhosts/ehcp/webmail>Login to webmail</a>'; //Enter your domain name here
}
?>
addemail.php
<?php session_start();
?>
<!--
Squirrelmail self register user account.
* Written by Jonathan Fraser (jon@unstoppables.org)for EHCP generated Squirrelmail.
*
* These scrips update a MYSQL database that stores the usernames and passwords. addemail.php calls adduser.php,
* checks for a password and an existing username, and adds the entered name into the table. Welcome email is sent
* and a confirmation email is sent to the administrator (or any existing account).
*
* CAPTCHA found at http://www.phpcaptcha.org by Drew Phillips <drew@drew-phillips.com> was used
* to prevent automated signup. The initial page (addemail.php)
* reuses Captcha's example_form.php adding my form instead of confirmation. securimage.php,
* securimage_show.php and elephant.tff are the required files. -->
<html>
<head>
<title>Add Email Account</title>
</head>
<body><center>
<?php
if (empty($_POST)) { ?>
<form method="POST">
<!-- pass a session id to the query string of the script to prevent ie caching -->
Enter text in picture and click Submit.<BR>
<img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br />
<input type="text" name="code" /><br />
<input type="submit" value="Submit" />
</form>
<?php
} else { //form is posted
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == true) {
$domainname='domain.org'; //Enter your domain name here
echo "<HTML>",
"<title>Add Email User - '$domainname' </title>",
"<body><br><br><div id='divMain' align='center'>",
"Adding domain/email user for domain: '$domainname' <br>",
"(do not write @domainname)<br>",
"<form method=post action=adduser.php> ",
"<table><tr><td>emailusername </td><td> ",
"<input type=text name=mailusername value=''>@'$domainname'",
"</td></tr><tr><td>password </td><td> ",
"<input type='password' name=password value=''></td></tr><tr><td>",
"<input type=hidden action=adduser.php></td></tr>",
"</table><input type=submit value='Submit'>",
"</form></div></body></html>";
} else {
echo "<center>Sorry, the code you entered was invalid. <a href=http://www.domain.org/addemail.php>to try again.</a></center>"; //Enter your domain name here
}
}
?>
</center>
</body>
</html>