Add mail users using php?

jimcarter

Well-Known Member
Jun 30, 2002
152
0
166
UK
i think he wants to prevent people from using an offensive name or something for their address
 

antifanatic

Member
Jul 11, 2002
5
0
151
yep thats right,also can any 1 make it to make forwarders as well please? also can they get it do a confirm to say its done or it hasnt.
 

Snowman

Member
Sep 9, 2002
14
0
151
I have been trying to utilise the signup script that is used on http://www.warwithboredom.com which allows users to signup for email acounts via a html form, however i cant seem to get the file to work.

If posts the username and password to the sql but isnt setting up the pop account.

The program consists of two files and a sql

the files are: config.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


$host = &www.yourdomain.com&;//your url
$domain = &yourdomain.com&;//your domain without the www
$cpaneluser = &username&;//your cpanel username
$cpanelpass = &password&;//your cpanel password
$cpaneltheme= &cpanelxp_hg&; //this is the word after frontend/ and the next / when you login to cpanel
$dbhost=&localhost&; //Usually localhost
$dbuser=&user&;//mysql username
$dbtable=&users&;//only change this if you have access to only one database
$dbpass=&&;//mysql password
$dbname=&users&;//The name of the database
$quota=4000;//how much space in k you want to give the user
$mailurl=&mail/index.php&;//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

?&



and


signup.php

&?php
$pathtoconfig=&config.php&;
include(&theme.php&);
doheader();
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 = '$username'))&;
$result= mysql_query($query,$link);
if(mysql_num_rows($result) ==0)
{
$query=&INSERT INTO $dbtable(name,username,password,email) VALUES ('$name','$newuser','$pass2','$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 );
?& Your account has been setup successfully please login &a href=&mail/index.php&&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&&
&table border=&0& cellspacing=&1& cellpadding=&0&&
&tr&
&td&Your full Name:&/td&
&td colspan=&2&&&input name=&name& type=&text&&&/td&
&/tr&
&tr&
&td width=&147&&Other Email Address:&/td&
&td colspan=&2&&&input name=&replymail& type=&text&&
(In case you forget your password)&/td&
&/tr&
&tr&
&td&Prefered Email Address:&/td&
&td colspan=&2&&&input name=&newuser& type=&text&&
@WarWithBoredom.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 (checkEmailAddress(document.orderform.replymail))
{
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)|(\.gov)|(\.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&
&? }
dofooter();
?&

the sql file is:

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;

Now im trying to use this but cant seem to get it to work.

My mail is horde which is available via :2095/horde/index.php and my cpanel theme is &cpanel&

anyone have any ideas what may be wrong with this code?
 

wooster

Member
Sep 23, 2002
7
0
151
Works great for me Snowman...Thanks for the script...Just one little thing... the quotas do not seem to work,.... it always comes out as unlimited ,any way tio get around it ??/
 

haruspex

Registered
Oct 23, 2002
1
0
151
[quote:fe903665a1][i:fe903665a1]Originally posted by wooster[/i:fe903665a1]

Works great for me Snowman...Thanks for the script...Just one little thing... the quotas do not seem to work,.... it always comes out as unlimited ,any way tio get around it ??/[/quote:fe903665a1]

A fix...
[mail.php]
// follow the instuctions given before...
// the config file is the same
&?
$pathtoconfig=&config.php&;
error_reporting(0);
if (!include($pathtoconfig)){echo&Cannot include config file.&br /&Please alert admin.\n&;die;}

if(isset($newuser)) {

$newemail = &$newuser@$domain&;

$link = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die(&Could not select database&);
$query=&SELECT username FROM $dbtable WHERE((username = '$username'))&;
$result= mysql_query($query,$link);
if(mysql_num_rows($result)==0) {
$query=&INSERT INTO $dbtable (name,username,password,email)
VALUES ('$name','$newuser','$password2','$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=$password2&quota=$quota\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n&;
fputs($socket,$in);
fclose( $socket );
?&Your account has been setup successfully please login &a href=&&?echo $mailurl;?&&&here&/a&. Use your full email address (&?echo $newemail;?&) as the username.&?
}
else {echo mysql_error();echo&&br /&Username already in use please try another one.&br /&&a href=\&&.$_SERVER['PHP_SELF'].&\&&Back&/a&&;}
mysql_close($link);
}

else { ?&
&form name=&orderform& method=&post& action=&&?echo$_SERVER['PHP_SELF'];?&&&
&table border=&0& cellspacing=&1& cellpadding=&0&&
&tr&
&td&Your full Name:&/td&
&td colspan=&2&&&input name=&name& type=&text& /&&/td&
&/tr&
&tr&
&td width=&147&&Other Email Address:&/td&
&td colspan=&2&&&input name=&replymail& type=&text& /&(In case you forget your password)&/td&
&/tr&
&tr&
&td&Prefered Email Address:&/td&
&td colspan=&2&&&input name=&newuser& type=&text& /&@&?echo $domain;?&&/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&&
&input name=&signupbtn& type=&button& id=&signupbtn& value=&Signup& onclick=&validateform();& /&
&/td&
&td width=&163&& &/td&
&/tr&
&/table&
&/form&

&script language=&JavaScript1.2&&
function validateform() {
if (checkEmailAddress(document.orderform.replymail)) {
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)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
if (goodEmail){good=1}
else {
alert('Please enter a valid e-mail address.');
field.focus();
field.select();
good=0;
}
return good;
}
&/script&
&?}?&

[/mail.php]
 

Snowman

Member
Sep 9, 2002
14
0
151
Ive got the code working as well now but im wondering if anyone knows of a bit of code that will bypass the popup login box that comes when you try to login to webmail.

I want to have a login box on my page where people can type in their username/password and it logs them straight into horde rather than promting them with a login box.

Anyone know of any code around to do that?
 

ThunderHostingDotCom

Well-Known Member
Nov 18, 2002
449
1
168
All over!
All features...

Ok, time to add my 2 cents. lol

I think we can all together come up with a kick $%^# webmail login feature for our clients. This is what I have done which in NO WAY compares to the PHP code that the above gents have submitted and it's not special either but I think it does a few things I seen people ask for. http://www.thunderhosting.com/mail/
1) Change email address password.
2) And a feature I think looks good to our clients but is probably never used is the ability to use their email over SSL. Which leads me to my questions/pleads for help...

1) I don't have an SSL cert installed on my server yet so how the heck does https://www.thunderhosting.com:2096/ work? I am stumped! I would think the page would come up as page not found but it logs into the account and gives the impression that they are over SSL but they are not are they & if so how?

SO a recap on what everyone would like is as follows...
1) Individual email users ability to manage email and edit account (EG: Change password) and view email over SSL without access to cPanel.
2) Admin ability to create, edit and delete accounts without access to cPanel.
3) Integration of these features on all domains on our server without having to edit each site. via Skins?
4) Integration into Skin(s) (EG: XController) without having to re-upload every time cPanel or XController update their software.

PLEASE let me know if I missed any request or if I have botched anyone's request up at all!

Now if someone out there would be so kind as to piece ALL of our ideas together into a cPanel Skin as default we would be set wouldn't we? Any takers?
 

stech4u

Member
Apr 5, 2003
8
0
151
wow...such a long thread that started simple... =)

i just hope that someone also solve the problem of having a quota on subdomains created through cpanel =\

oh well...
 

TDD

Active Member
Dec 21, 2002
38
0
156
I am using this below code for email forward...but its not creating email forward when i log in and check in cpanel....when form is submitted it doesnt give any error..just a blank page so i guess its executing well.

Can someone help me please.......

Thanks
TDD

<?
if ($submit){
$host = "www.xx.com";
$domain = "xx.com";
$socket = fsockopen($host,2082);

// these lines are changed
$cpaneluser = "xyz";
$cpanelpass = "xyz";
$authstr = "$cpaneluser:$cpanelpass";
//****************************

$pass = base64_encode($authstr);
$in = "GET /frontend/x/mail/doaddfwd.html?email=$email&domain=$domain&forward=$forward HTTP/1.0\r\nAuthorization: Basic $pass \r\n";

fputs($socket,$in);
fclose( $socket );
}
else {
?>
<form method=post>
Email:<input type=text name=email>
Domain:<input type=text name=domain>
Forward To:<input type=text name=forward>
<input type=submit name=submit>
<?
}
?>
 

dobchik

Registered
Dec 25, 2003
1
0
151
Hi!
I am not a guru and I might be wrong (though I do not think so) but isnt it very unsecure to put cpanel (read root) password in to a script???? And send it through GET?? Even though it is not going to be seen in the browser it is still could be traced.
But anyway! Root password should not even be on the paper! And especially not in a script...
 
Last edited:

OmegaQuest

Registered
Oct 18, 2003
2
0
151
Why does this not work anymore?

http://USERNAME:PASSWORD@DOMAIN:2082

to log into your cPanel ?

I would like to know this because I have everything set up for a script to run a command to create an E-mail via cPanel but that link dosent work because of the above question dosent seem to work with cPanel, did they disable logging into cPanel like that ?

Here is the Code:
Code:
http://USERNAME:PASSWORD@DOMAIN:2082/frontend/$cpmod/mail/doaddpop.html?email=$email&domain=$domain&password=$password&quota=$quota
 

OmegaQuest

Registered
Oct 18, 2003
2
0
151
I just need a Way around my problem...

I have a script already made and its so worked into my site, that I cant replace it....

Thanks
 

longtech

Registered
Nov 15, 2004
3
0
151
Can anyone tell me how to run the signup script? I saved the scripts to config.php and signup.php and uploaded to my server. And then I run signup.php from browser but it just echo back some of the content of the script. Why is that? I know my system can run php scripts. Thanks.
 

longtech

Registered
Nov 15, 2004
3
0
151
Snowman said:
Ive got the code working as well now but im wondering if anyone knows of a bit of code that will bypass the popup login box that comes when you try to login to webmail.

I want to have a login box on my page where people can type in their username/password and it logs them straight into horde rather than promting them with a login box.

Anyone know of any code around to do that?
Thanks for the script. But why do I see a lot of '&amp;' in your script? Display problem? Thanks.
 

hph

Registered
Nov 26, 2004
1
0
151
heres a great free script

i use the script from here
http://scripts.freemans-web.com

it does everything, creates mail, creates a subdomain,creates a ftp account and even a mysql db. everything works great except for linking the right password to the new mysql db.
brian did a geat job for a free script but be nice to get the new db working right
 

cdunlap

Registered
Jul 18, 2006
1
0
151
DANGER WILL ROBINSON!!!

If the user var is blank in the HTTP request for the "realdelpop.html" page, but the domain contains a value. It will wipe out every email account for the entire domain.

BE CAREFUL.... I learned the hard way :eek:

Should cPanel be addressing this as a possible bug? It seems rather easy to remove every email account accidently using a program. I'd suggest putting in a check to see if the user var is blank, if so, do nothing.