I know it's an old topic, however....
I know this is an old topic, however, I needed a script to add the e-mail accounts and ran accross this thread. The code posted was all mixed up with "amps" etc. so it could not be copied directly from the thread. I've gone ahead and cleaned up the code and fixed some problems that were in it like the quota's not being setup, and some variables that were wrong.
Here is the code for each file:
signup.php
config.php
and the sql file that needs to be run after you create the database:
A couple other items I would recommend when using this script. Place your config.php file outside of your public_html folder, and set the path in the $pathtoconfig. Since this file contains your cpanel username/password you don't want it placed inside the public_html folder where it can be read by the world....
Second, place the signup.php file in it's own directory and setup a web protect on that directory so it is password protected (unless of course you want anyone to be able to access it).
Regards,
Damion McHenry
www.interXstream.com
I know this is an old topic, however, I needed a script to add the e-mail accounts and ran accross this thread. The code posted was all mixed up with "amps" etc. so it could not be copied directly from the thread. I've gone ahead and cleaned up the code and fixed some problems that were in it like the quota's not being setup, and some variables that were wrong.
Here is the code for each file:
signup.php
PHP:
<?php
if(isset($newuser))
{
include($pathtoconfig);
$newemail = "$newuser@$domain";
$mpassword = $password2;
$link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die("Could not select database");
$query="SELECT username FROM $dbtable WHERE((username = '$newuser'))";
$result= mysql_query($query,$link);
//echo mysql_num_rows($result);
if(mysql_num_rows($result) == 0)
{
$query="INSERT INTO $dbtable(name,username,password,email) VALUES ('$name','$newuser','$mpassword','$replymail');";
mysql_query($query,$link);
$socket = fsockopen($host,2082);
$authstr = "$cpaneluser:$cpanelpass";
$pass = base64_encode($authstr);
$in = "GET /frontend/$cpaneltheme/mail/doaddpop.html?email=$newemail&domain=$domain&password=$mpassword"a=$quota\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n";
fputs($socket,$in);
fclose( $socket );
?> <BR><BR>Your account has been setup successfully please login <a href="<? echo "$mailurl";?>">here</a>
<?
}
else {
echo "Username already in use please try another one.<br><a href=signup.php>Back</a>";
}
mysql_close($link);
}
else { ?>
<form name="orderform" method="post" action="signup.php">
<p> </p>
<p> </p>
<table border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td>Your full Name:</td>
<td colspan="2"><input name="name" type="text"></td>
</tr>
<tr>
<td>Prefered Email Address:</td>
<td colspan="2"><input name="newuser" type="text">
@yourdomain.com</td>
</tr>
<tr>
<td>Password:</td>
<td colspan="2"><input name="password1" type="password"></td>
</tr>
<tr>
<td>Retype Password:</td>
<td colspan="2"><input name="password2" type="password"></td>
</tr>
<tr>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td> </td>
<td width="344"> <div align="center">
<input name="signupbtn" type="button" id="signupbtn" value="Signup" onClick="validateform()">
</div></td>
<td width="163"> </td>
</tr>
</table>
<script language="JavaScript1.2">
function validateform()
{
if(document.orderform.password1.value == document.orderform.password2.value)
{
document.orderform.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)|(\.go v)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail){
good = true
} else {
alert('Please enter a valid e-mail address.')
field.focus()
field.select()
good = false
}
return good;
}
</script>
</form>
<? }
?>
config.php
PHP:
<?
//before this will work you will need to make a database and then run signup.sql in phpmyadmin
//if you need any help email me at [email protected]
//also once you have made the table you Must add any email addresses that you already have
//to the data base manually otherwise this script can overwrite mailboxes
$pathtoconfig="config.php";
$host = "www.yourdomain.com";//your url
$domain = "yourdomain.com";//your domain without the www
$cpaneluser = "usernmae";//your cpanel username
$cpanelpass = "password";//your cpanel password
$cpaneltheme= "themename"; //this is the word after frontend/ and the next / when you login to cpanel
$dbhost="localhost"; //Usually localhost
$dbuser="databaseuser";//mysql username
$dbtable="users";//only change this if you have access to only one database
$dbpass="dbpass";//mysql password
$dbname="databasename";//The name of the database
$quota=100;//how much space in k you want to give the user
$mailurl="http://yourdomain/webmail";//The url for your web based mail program I use http://uebimiau.sourceforge.net but you can use anything
//see http://www.hotscripts.com/PHP/Scripts_and_Programs/Email_Systems
//End of settings! you should not need to change anything below this
?>
PHP:
CREATE TABLE `users` (
`name` char(50) NOT NULL default '',
`username` char(50) NOT NULL default '',
`password` char(20) NOT NULL default '',
`id` int(11) NOT NULL auto_increment,
`email` char(50) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
A couple other items I would recommend when using this script. Place your config.php file outside of your public_html folder, and set the path in the $pathtoconfig. Since this file contains your cpanel username/password you don't want it placed inside the public_html folder where it can be read by the world....
Second, place the signup.php file in it's own directory and setup a web protect on that directory so it is password protected (unless of course you want anyone to be able to access it).
Regards,
Damion McHenry
www.interXstream.com