Let Users create their own accounts (Upgraded for 4.3)

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Let Users create their own accounts (Upgraded for 4.3)

Post by ^DooM^ » 2006-11-17 13:25

The old script was broken and not even slightly secure so here is an updated version to allow your users to create their own accounts.

Thanks to pccsq1 for his work in upgrading it to work for 4.3 and the original author whoever they might be :)

There is another script that has been re-written here. Take your pick :)

Code: Select all

<?php

//MySQL Information:
$mysql_host = "localhost"; //Host Name
$mysql_user = ""; //Username
$mysql_pass = ""; //Password
$mysql_db = "hmailserver"; //Database

//General Configuration:
$form_title = "signup"; //Name for this form
$account_max = "10000000"; //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!)

$admin_notify = 1; //1 = yes & 0 = no
$admin_email = ""; //Administrators email to send notifications)
$admin_default_activate = 1; //1 = yes & 0 = no -> If no, the administrator has to authorise the account
$encryption = 2; //Password encryption level

//DO NOT EDIT BELOW!//

// Protect the Database and MD5 the password.
$strName    = addslashes( $_POST['name'] );
$strUser    = addslashes( $_POST['user'] );
$strDomain  = addslashes( $_POST['domain'] );
$strPass1   = addslashes( $_POST['pass1'] );
$strMD5Pass = md5( $strPass1 );

error_reporting(E_ALL ^ E_NOTICE);
//Next two lines connect to database using information from above.
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
$select = mysql_select_db($mysql_db);

IF (!$open || !$select) 
{ 
    echo "Unable to open database, contact your administrator!"; 
}
ELSE
{
    echo "<font size=\"+2\">$form_title</font><br><br>"; //Display form title from above
    //Decide On What Path To Take
    SWITCH ($_GET['mode'])
    {
    CASE "do":
        //#### PAGE IF FORM FILLED OUT ####//
        $q=mysql_query("SELECT * FROM `hm_domains` WHERE `domainid` = '{$strDomain}' LIMIT 1"); //Load Domain Into memory (internal use)
        WHILE ($v=mysql_fetch_array($q)) 
        { 
            $temp_domain = $v['1']; 
        
        } //Apply information

        $q2=mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$temp_domain' LIMIT 1"); //Check if account exists
        $v2=mysql_num_rows($q2); //Gets number of accounts that exist with that profile (should be less than or equal to one)
        
        IF ($v2 == 1) 
        { 
            echo "A user with this username already exists! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
        }
        ELSE
        {
            IF (!$_POST['pass1'] || !$_POST['pass2']) 
            { 
                echo "You did not enter both passwords! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
            }
            ELSEIF ($_POST['pass1'] <> $_POST['pass2']) 
            { 
                echo "Your passwords do not match! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
            }
            ELSE
            {
                $q3=mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$strDomain','$strUser@$temp_domain','$strMD5Pass','$admin_default_activate','0','$account_max','$encryption')") or die(mysql_error());
            }
        }
        
        IF ($q3)
        {
            IF ($admin_default_activate == 0)
            {
                echo "Your account has been created <b>however requires administrator activation.</b> You should receive a message soon regarding this.";
            }
            ELSE
            {
                echo "Your account has been created and is ready for use!<br><br>Username: $strUser@$temp_domain<br><br>Webmail: <a href=\"$serv_webmail/webmail\">www.$temp_domain/webmail</a><br>POP3: mail.$temp_domain<br>IMAP: mail.$temp_domain<br><br>SMTP: mail.$temp_domain";
                $subject = "Welcome To MYWEBSITE!";
                $message = "This is confirmation that your account has been created.";

                mail("{$_POST['user']}@$temp_domain", $subject, $message); //Send welcome message
            }
        }
        ELSE
        {
            echo "Database error, unable to add account. Please contact your administrator!";
        }

        IF ($admin_default_activate == 0 && $admin_notify == 0)
        {
            $admin_mail_subject = "Account Requires Activation!";
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']} and needs to be activated!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message);
        }
        ELSEIF ($admin_default_activate == 1 && $admin_notify == 1)
        {
            $admin_mail_subject = "New Account Created!";
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']}!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message);
        }
         ELSEIF ($admin_default_activate == 0 && $admin_notify == 1)
        {
            $admin_mail_subject = "New Account Created!";
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']}!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message);
        }
        break;
    
    DEFAULT:
    }
}

//#### MAIN PAGE IF FORM NOT FILLED OUT ####//
echo "
<form action=\"?mode=do\" method=\"POST\">
Your Name: <input type=\"text\" name=\"name\" size=\"21\"><br>
E-Mail: <input type=\"text\" name=\"user\" size=\"21\"> @ <select name=\"domain\">
";

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains
{
    echo "<option value=\"{$v2['0']}\">{$v2['1']}</option>";
}

echo "
</select><br>
Password: <input type=\"password\" name=\"pass1\" size=\"21\"><br>
Password: <input type=\"password\" name=\"pass2\" size=\"21\"> (For Confirmation)<br><br>

<input type=\"submit\" value=\"Create Account\">
</form>
";
?>
If you come across any errors please let me know.

Cheers
Last edited by ^DooM^ on 2006-11-29 11:20, edited 3 times in total.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2006-11-17 14:12

Hi Doom,

Thanks for the modifications. :D

The script work very well. It's a good thing we got it working with the errors sorted as am sure it will be useful to some of the others on this forum.

I am also posting the other script done to display only a suer's domain for the amil signup instead of all the domains on hmailserver.

Code: Select all

<?php 

//SINGLE DOMAIN SIGNUP
//---------------------------------------

//MySQL Information:
$mysql_host = "localhost"; //Host Name
$mysql_user = ""; //Username
$mysql_pass = ""; //Password
$mysql_db = "hmailserver"; //Database

//General Configuration:
$form_title = "signup"; //Name for this form
$account_max = "10000000";  //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!)

$admin_notify = 1; //1 = yes & 0 = no
$admin_email = ""; //Administrators email to send notifications)
$admin_default_activate = 1; //1 = yes & 0 = no -> If no, the administrator has to authorise the account
$encryption = 2; //Password encryption level

$url = $_SERVER["HTTP_HOST"];
$domain = $_SERVER["HTTP_HOST"];

if (substr($domain,0,4) == "www.")
        {
                $domain = strstr($domain, ".");
                $domain = substr($domain, 1);
        }

// Protect the Database and MD5 the password. 
$strName    = addslashes( $_POST['name'] ); 
$strUser    = addslashes( $_POST['user'] ); 
$strDomain  = addslashes( $_POST['domain'] ); 
$strPass1   = addslashes( $_POST['pass1'] ); 
$strMD5Pass = md5( $strPass1 ); 

error_reporting(E_ALL ^ E_NOTICE); 
//Next two lines connect to database using information from above. 
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
$select = mysql_select_db($mysql_db); 

IF (!$open || !$select) 
{ 
    echo "Unable to open database, contact your administrator!"; 
} 
ELSE 
{ 
    echo "<font size=\"+2\">$form_title</font><br><br>"; //Display form title from above 
    //Decide On What Path To Take 
    SWITCH ($_GET['mode']) 
    { 
    CASE "do": 
        //#### PAGE IF FORM FILLED OUT ####// 
        $q=mysql_query("SELECT * FROM `hm_domains` WHERE `domainid` = '{$strDomain}' LIMIT 1"); //Load Domain Into memory (internal use) 
        WHILE ($v=mysql_fetch_array($q)) 
        { 
            $temp_domain = $v['1']; 
        
        } //Apply information 

        $q2=mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$temp_domain' LIMIT 1"); //Check if account exists 
        $v2=mysql_num_rows($q2); //Gets number of accounts that exist with that profile (should be less than or equal to one) 
        
        IF ($v2 == 1) 
        { 
            echo "A user with this username already exists! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
        } 
        ELSE 
        { 
            IF (!$_POST['pass1'] || !$_POST['pass2']) 
            { 
                echo "You did not enter both passwords! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
            } 
            ELSEIF ($_POST['pass1'] <> $_POST['pass2']) 
            { 
                echo "Your passwords do not match! <a href=\"javascript:history.go(-1)\">Go Back</a>"; 
            } 
            ELSE 
            { 
                $q3=mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$strDomain','$strUser@$temp_domain','$strMD5Pass','$admin_default_activate','0','$account_max','$encryption')") or die(mysql_error()); 
            } 
        } 
        
        IF ($q3) 
        { 
            IF ($admin_default_activate == 0) 
            { 
                echo "Your account has been created <b>however requires administrator activation.</b> You should receive a message soon regarding this."; 
            } 
            ELSE 
            { 
                echo "Your account has been created and is ready for use!<br><br>Username: $strUser@$temp_domain<br><br>Webmail: <a href=\"$serv_webmail/webmail\">www.$temp_domain/webmail</a><br>POP3: mail.$temp_domain<br>IMAP: mail.$temp_domain<br><br>SMTP: mail.$temp_domain"; 
                $subject = "Welcome To MYWEBSITE!";
                $message = "This is confirmation that your account has been created."; 

                mail("{$_POST['user']}@$temp_domain", $subject, $message); //Send welcome message 
            } 
        } 
        ELSE 
        { 
            echo "Database error, unable to add account. Please contact your administrator!"; 
        } 

        IF ($admin_default_activate == 0 && $admin_notify == 0) 
        { 
            $admin_mail_subject = "Account Requires Activation!"; 
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']} and needs to be activated!"; 
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 1 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']}!"; 
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 1 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']}!"; 
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 0 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$temp_domain has been created by {$_POST['name']}!"; 
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        break; 
    
    DEFAULT: 
    } 
} 

//#### MAIN PAGE IF FORM NOT FILLED OUT ####// 
echo " 
<form action=\"?mode=do\" method=\"POST\"> 
Your Name: <input type=\"text\" name=\"name\" size=\"21\"><br> 
E-Mail: <input type=\"text\" name=\"user\" size=\"21\"> @ <select name=\"domain\"> 
"; 

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory 
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains 
{ 
    echo "<option value=\"{$v2['0']}\">$domain</option>";
} 

echo " 
</select><br> 
Password: <input type=\"password\" name=\"pass1\" size=\"21\"><br> 
Password: <input type=\"password\" name=\"pass2\" size=\"21\"> (For Confirmation)<br><br> 

<input type=\"submit\" value=\"Create Account\"> 
</form> 
"; 
?>
I hope we can all benefit from our varying spheres of knowledge however mediocre. I have learnt some sueful stuff in the course of this issue.

Many thanks to Martin and of course, Doom!!!

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-11-28 14:26

Hi Guys

Thanks for the great scripts.
Can some please explain to a "script illiterate" person (thats me BTW) :roll: how to change the look of the form. eg, centre the form, etc.

Cheers

Oh, one more thing, when I tested the script and clicked the "Create Account" button, the browser tries to load a page "email.php?mode=do". Where is this?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-11-28 16:01

no1uno wrote:Hi Guys

Thanks for the great scripts.
Can some please explain to a "script illiterate" person (thats me BTW) :roll: how to change the look of the form. eg, centre the form, etc.

Cheers

Oh, one more thing, when I tested the script and clicked the "Create Account" button, the browser tries to load a page "email.php?mode=do". Where is this?
Hi no1Uno,

You will need to use a table or <div> to align the html to the center you can see how to do this on any HTML tutorial website.

The reason it is trying to load email.php is because you need to call your actual php script email.php

HTH
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2006-11-28 16:49

Hi,

Adding on to what Doom has advised regarding the form submitting to itself (email.php), if you want to use another name for your form, you can just change the form name and also remember to chenge the action="" vlue to the form name you have changed it to.

Hope this helps.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-11-28 18:47

Actually thinking about this you can just change the form from

Code: Select all

<form action=\"email.php?mode=do\" method=\"POST\">
to

Code: Select all

<form action=\"?mode=do\" method=\"POST\">
It should work then for whatever name the script is called :)

I have modified the previous posts to reflect this.

User avatar
bagu
Senior user
Senior user
Posts: 275
Joined: 2005-06-17 03:08
Location: France
Contact:

Post by bagu » 2006-11-29 03:17

unfortunatly not xhtml compliant :(

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-11-29 03:50

Ok, I think I understand. Just to confirm:

If I save the script to my server and call it "signup.php" then I need to change

Code: Select all

email.php?mode=do
to

Code: Select all

signup.php?mode=do
Correct?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-11-29 04:00

Thats correct or just omit the script name completely and just have ?mode=do there instead.

bagu is that really necessary then for a signup script that will be viewed once?

I understand the need for compliance but I do believe that there is a place for it. What we have here is mainly a backend script with a frontend quickly thrown on. In my opinion it could be done better but for how much it will be used I will not lose any sleep over it ;)

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-11-29 10:24

Thanks ^DooM^

Not sure if you can help with the modified script thats used for a single domain, or wait for pccsq1, but I have a question.

The modified part of the script

Code: Select all

if (substr($domain,0,4) == "www.") 
        { 
                $domain = strstr($domain, "."); 
                $domain = substr($domain, 1); 
I have tried to change the domain ID from 1 to 2, but it has made no difference it still adds the user to domain ID 4
I checked the database and the domain I want to use is definately ID 2.

Any ideas.
Thanks

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2006-12-04 19:50

Hi no1uno,

The section of the script you have described IS NOT actually for domain selection. It is to parse a domain name from the url where ther script is run from and pass it to the script as the domain value.

For clarity, if you have users you host or wish to run this script at different locations without having to display all the domains hosted on your server, then the domain parsing section simply extracts the domain name from the url where it is run from. For instance, if the script is located at http://www.abcdomain.com or http://www.abcdomain.com, then the script will take "abcdomain.com" and assign it as the domain value for the script t use.

I have made a custom page with the single domain script for some of users to allow people that user their websites to signup for email accounts in just the same way that you would go to any free email site and signup for an email account.

I hope this helps.

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-12-05 10:19

Thanks pccsq1. I sort of undestand how that piece of coding now works.

The problem I having is :
It does show the current domain name as you described, however as I have 4 domains on HMS, the drop down box gives 4 options of the same domain name. Now this wouldn't be too much of a problem, but although it shows the same domain, when you create the user it uses one of the other domains on HMS

Thanks to all so far. :D

nblbmx880
New user
New user
Posts: 7
Joined: 2006-12-04 10:52
Location: USA
Contact:

Post by nblbmx880 » 2006-12-06 00:13

what is the database to mysql? my sql is located at C:/webserver/htdocs/phpmyadmin. so do i put that or one of the folders inside??

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-12-06 01:07

your mysql install is not located where you think it is. phpmyadmin is just a frontend application that allows you to easily administer mysql.

I am guessing you do not run this server yourself. You should talk to your admin about where it has been installed unless you are talking about hmail servers mysql server then the default location is C:/program files/hmailserver/mysql/bin/

I belive what you actually need is the IP address which if it is on the same machine will be localhost ( 127.0.0.1 ).

nblbmx880
New user
New user
Posts: 7
Joined: 2006-12-04 10:52
Location: USA
Contact:

Post by nblbmx880 » 2006-12-06 01:11

i actually have my own server and host this my self. and thank you i think that should help. Thanks so much

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-12-14 03:51

Can someone please explain this piece of code.

Code: Select all

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory 
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains 
{ 
    echo "<option value=\"{$v2['0']}\">$domain</option>"; 
} 
I am thinking it queries the HMS database and returns all the domain names.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2006-12-14 04:44

That is correct.

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-12-14 07:21

Great, thanks Doom. Now for the next question.
Can the code be changed to return only one domain. Something like:

Code: Select all

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory 
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains 
{ 
    echo "<option value="$domainid=2"</option>"; 
} 
I know pccsq1 has modified the script to do this, and it does change all options to one domain name, however it seems that this one piece of code:

Code: Select all

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory 
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains 
{ 
    echo "<option value=\"{$v2['0']}\">$domain</option>"; 
} 
is still returning all the domain ID's.
Thanks

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2006-12-21 10:46

Hello no1uno,

Replace the old form I posted for single domain signup with the following. I have made the necessary modifications to stop it giving multiple outputs of the same domain:

Code: Select all


<?php 

//MySQL Information: 
include("..\email.inc.php");

$url = $_SERVER["HTTP_HOST"];
$domain = $_SERVER["HTTP_HOST"];

if (substr($domain,0,4) == "www.")
        {
                $domain = strstr($domain, ".");
                $domain = substr($domain, 1);
        }

// Protect the Database and MD5 the password. 
$strName    = addslashes( $_POST['name'] ); 
$strUser    = addslashes( $_POST['user'] ); 
$strDomain  = addslashes( $_POST['domain'] ); 
$strPass1   = addslashes( $_POST['pass1'] ); 
$strMD5Pass = md5( $strPass1 ); 

error_reporting(E_ALL ^ E_NOTICE); 
//Next two lines connect to database using information from above. 
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
$select = mysql_select_db($mysql_db); 

IF (!$open || !$select) 
{ 
    echo "Unable to open database, contact your administrator!"; 
} 
ELSE 
{ 
    echo "<font size=\"+2\">$form_title</font><br><br>"; //Display form title from above 
    //Decide On What Path To Take 
    SWITCH ($_GET['mode']) 
    { 
    CASE "do": 
        //#### PAGE IF FORM FILLED OUT ####// 
        $q=mysql_query("SELECT * FROM `hm_domains` WHERE `domainid` = '{$strDomain}' LIMIT 1"); //Load Domain Into memory (internal use) 
        WHILE ($v=mysql_fetch_array($q)) 
        { 
        } //Apply information

        $q2=mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$strDomain' LIMIT 1"); //Check if account exists
        $v1=mysql_num_rows($q2); //Gets number of accounts that exist with that profile (should be less than or equal to one)
        
        IF ($v1 == 1)
        { 
            echo "A user with this username already exists!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
        } 
        ELSE 
        { 
            IF (!$_POST['pass1'] || !$_POST['pass2']) 
            { 
                echo "You did not enter both passwords!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
            } 
            ELSEIF ($_POST['pass1'] <> $_POST['pass2']) 
            { 
                echo "Your passwords do not match!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
            } 
            ELSE 
            { 
                $q3=mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$strDomain','$strUser@$strDomain','$strMD5Pass','$admin_default_activate','0','$account_max','$encryption')") or die(mysql_error());
            } 
        } 
        
        IF ($q3) 
        { 
            IF ($admin_default_activate == 0) 
            { 
                echo "Your account has been created <b>however requires administrator activation.</b> You should receive a message soon regarding this."; 
            } 
            ELSE 
            { 
                echo "Your account has been created and is ready for use!<br><br>Username: $strUser@$strDomain<br><br>Webmail: <a href=\"$serv_webmail/webmail\">www.$strDomain/webmail</a><br>POP3: mail.$strDomain<br>IMAP: mail.$strDomain<br><br>SMTP: mail.$strDomain";
                $subject = "Welcome To HOME1NET!";
                $message = "This is confirmation that your account has been created."; 

                mail("{$_POST['user']}@$strDomain", $subject, $message); //Send welcome message
            } 
        } 
        ELSE 
        { 
            echo "Database error, unable to add account. Please contact your administrator!"; 
        } 

        IF ($admin_default_activate == 0 && $admin_notify == 0) 
        { 
            $admin_mail_subject = "Account Requires Activation!"; 
            $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']} and needs to be activated!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 1 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 1 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        ELSEIF ($admin_default_activate == 0 && $admin_notify == 1) 
        { 
            $admin_mail_subject = "New Account Created!"; 
            $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
            mail($admin_email, $admin_mail_subject, $admin_mail_message); 
        } 
        break; 
    
    DEFAULT: 
    } 
} 

//#### MAIN PAGE IF FORM NOT FILLED OUT ####// 
echo " 
<form action=\"?mode=do\" method=\"POST\">
Your Name: <input type=\"text\" name=\"name\" size=\"21\"><br> 
E-Mail: <input type=\"text\" name=\"user\" size=\"21\"> @ <select name=\"domain\"> 
"; 

$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory
{
    echo "<option name=\"domain\">$domain</option>";
} 

echo " 
</select><br> 
Password: <input type=\"password\" name=\"pass1\" size=\"21\"><br> 
Password: <input type=\"password\" name=\"pass2\" size=\"21\"> (For Confirmation)<br><br> 

<input type=\"submit\" value=\"Create Account\"> 
</form> 
"; 
?>

I hope this solves your problem. Let me know if you need anything else.

no1uno
Normal user
Normal user
Posts: 66
Joined: 2006-08-06 10:29
Location: Australia
Contact:

Post by no1uno » 2006-12-21 17:05

Works like a charm pccsq1. Thank you very much.

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 01:26

I'm trying to implement this myself, and have some connect errors to the database, hopefully this'll be a snap for someone.

The link to the errors:
http://webmail.eagle-scout.net/email.php

Thanks a LOT!!!

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-01-04 01:47

The error states Unable to open database

Which means you need to check your config values. Make sure you have the correct database name, user and password entries.

Also make sure the IP connecting to the mysql database has the correct permissions to access that database.

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 05:00

Sorry, I feel dumb for asking this but how do I find out what the name of the mysql database that is installed with the regular hmail installation?

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 05:43

Ok, I've found the exact name of the database, placed that in the code... I've put the username and password i use to get into the phpWebAdmin site into the code, but I still get the error listed above at the link. Could there be a port issue? Again, I really appreciate the help. :)

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-01-04 10:11

you will need to setup the default mysql port in your php.ini to 3307 as the default install of hmails internal mysql uses a non standard port.

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 15:48

Argh... sorry I swear I'm learning from this.... I have a connection, but the username and password is wrong, even though it's the one I've put in the code... http://webmail.eagle-scout.net/email.php

Again, thanks, a bunch.

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 16:14

One more thing, I'm not sure where the ODBC user is coming from as I'm not using odbc rather mysql.....

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 17:03

PROGRESS! Ok, so I found that I had to decrypt a password, like I said, I'm learning! So, now I have a few other errors, hopefully easy ones and the fact that it's not stripping webmail from the host header, I changed the www in the code to webmail. Any thoughts on this one? Again, thank you!

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 18:21

I've got this working now, however it doesn't seem to add the account in the PHPAdmin or the hmailserver administrator on the server. It sends me an email telling me that it needs to be activated, is there another script for doing this?? thanks a bunch!

User avatar
katip
Senior user
Senior user
Posts: 1161
Joined: 2006-12-22 07:58
Location: Istanbul

Errors

Post by katip » 2007-01-04 20:28

I saved the script as it is as "signup.php".
When I call it following errors are displayed:

Notice: Undefined index: name in C:\Jana2\html\katip\cgi-bin\WebMail\src\signup.php on line 21

Notice: Undefined index: user in C:\Jana2\html\katip\cgi-bin\WebMail\src\signup.php on line 22

Notice: Undefined index: domain in C:\Jana2\html\katip\cgi-bin\WebMail\src\signup.php on line 23

Notice: Undefined index: pass1 in C:\Jana2\html\katip\cgi-bin\WebMail\src\signup.php on line 24

Then the form is displayed correctly. What am I doing wrong?
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

bartley
New user
New user
Posts: 18
Joined: 2007-01-02 16:14

Post by bartley » 2007-01-04 21:22

yep, I have it working, but I definatly can't see the added email addresses in either of the administration sites, the php version or the one running on the server. lol

spudnik282
New user
New user
Posts: 1
Joined: 2007-01-29 03:42

Post by spudnik282 » 2007-02-02 23:35

Hi,
When I go to create a new user with this script I receive the following error "Field 'accountadminlevel' doesn't have a default value"

I've searched the the file looking for 'accountadminlevel' with out success.

I granted the account used to access the database every available privilege with no success.

Any ideas on how to fix this would be greatly appreciated!

Thanks,
Spud

User avatar
BOOZy
Normal user
Normal user
Posts: 80
Joined: 2006-05-25 01:25
Location: .nl
Contact:

Post by BOOZy » 2007-02-05 15:22

Just adding some info:
If you're using the build in database on port 3307, you don't need to edit your php.ini, just change "localhost" to "localhost:3307".

User avatar
BOOZy
Normal user
Normal user
Posts: 80
Joined: 2006-05-25 01:25
Location: .nl
Contact:

Post by BOOZy » 2007-02-05 15:39

Warning: mail() [function.mail]: SMTP server response: 451 Please try again later. in \email.php on line 86

Warning: mail() [function.mail]: SMTP server response: 503 Must have sender and recipient first. in \email.php on line 104


Oops?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-05 18:49

451 try again later is greylisting at work. you would need to disable spam protection for local ipranges. not sure what is causing the second error though.

User avatar
[PT]Cableguy
New user
New user
Posts: 25
Joined: 2007-02-22 11:09
Location: Portugal

Post by [PT]Cableguy » 2007-02-23 16:37

^DooM^ wrote:....You will need to use a table or <div> to align the html to the center you can see how to do this on any HTML tutorial website....
Sorry for this newbie question, but the best i could do was to create a table and align the content of it:
Image
With the following changes:

Code: Select all

//#### MAIN PAGE IF FORM NOT FILLED OUT ####// 

echo " 
<form action="?mode=do" method="POST">
<table style='border:1px solid #000000;'>
<tr>
<td align='left'>
Nome    : <input type="text" name="name" size="21"><br> 
E-Mail: <input type="text" name="user" size="21"> @ <select name="domain"> 
"; 
$q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC"); //Load avaliable domains into memory 
WHILE ($v2=mysql_fetch_array($q2)) //Display avaliable domains 
{ 
    echo "<option value="{$v2['0']}">{$v2['1']}</option>"; 
} 
echo " 
</select><br>
Password: <input type="password" name="pass1" size="21"><br>
Password: <input type="password" name="pass2" size="21"> (confirmação)<br><br>
<input type="submit" value="Criar conta"> 
</td>
</tr>
</table>
</form> 
";
?>
I'm still no able to center the entire "text" when visualizing in the browser.
Can someone help me, please?
aka: Bruno Vaz

hMailServer-4.3.1-B253 + phpwebadmin + roundcubemail-0.1beta2.2 + clamwin-0.88.7

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-23 17:19

Change

Code: Select all

<form action=\"?mode=do\" method=\"POST\">
to

Code: Select all

<div align=\"center\"><form action=\"?mode=do\" method=\"POST\">
And

Code: Select all

</form>
to

Code: Select all

</form></div>
That should center it on the page.

User avatar
[PT]Cableguy
New user
New user
Posts: 25
Joined: 2007-02-22 11:09
Location: Portugal

Post by [PT]Cableguy » 2007-02-23 17:59

YAHOOOOOO !!!! Thanks ^DooM^ for you're support !!!

(It's amazing, but sometimes...simple things are harder to accomplish.)
aka: Bruno Vaz

hMailServer-4.3.1-B253 + phpwebadmin + roundcubemail-0.1beta2.2 + clamwin-0.88.7

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-24 03:08

You are welcome :)

User avatar
katip
Senior user
Senior user
Posts: 1161
Joined: 2006-12-22 07:58
Location: Istanbul

It's woking, but...

Post by katip » 2007-02-24 07:32

Thanks for this handy script and sorry for asking same question once again:
I've copied/saved above script as signup.php, made proper mods and fired it from mydomain.com/cgi-bin/signup.php
Following errors are displayed on top of the page:

Notice: Undefined index: name in C:\(blah...)\cgi-bin\signup.php on line 21
Notice: Undefined index: user in C:\(blah...)\cgi-bin\signup.php on line 22
Notice: Undefined index: domain in C:\(blah...)\cgi-bin\signup.php on line 23
Notice: Undefined index: pass1 in C:\(blah...)\cgi-bin\signup.php on line 24

The rest of the page is ok (form displayed correctly). Also it works as desired. Accounts are created, confirmation comes etc..

Now, how to avoid those error lines? TIA
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-24 13:58

Does the script work? Are you including this script from another script or using it standalone?

Have you entered anything into the boxes when you get these errors or are you just leaving them blank as there is no error checking in that script and would throw up warnings if the boxes were empty.

User avatar
katip
Senior user
Senior user
Posts: 1161
Joined: 2006-12-22 07:58
Location: Istanbul

Post by katip » 2007-02-24 17:31

^DooM^ wrote:Does the script work? Are you including this script from another script or using it standalone?

Have you entered anything into the boxes when you get these errors or are you just leaving them blank as there is no error checking in that script and would throw up warnings if the boxes were empty.
Hi Doom,
I've copied/saved above script as signup.php
I'm running it standalone by entering "mydomain.com/cgi-bin/signup.php" in the address bar. The page comes as desribed above.
The script works as expected but those error lines are displayed at first run.
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-24 17:35

They aren't error messages they are notices. Are you running PHP5?

User avatar
katip
Senior user
Senior user
Posts: 1161
Joined: 2006-12-22 07:58
Location: Istanbul

Post by katip » 2007-02-24 17:46

^DooM^ wrote:They aren't error messages they are notices. Are you running PHP5?
PHP 5.1.2
Yes, they are notices. I'm not a PHP expert but assume that it's reading script lines in their sequence. Those lines causing the notices are statements about not (yet) defined variables as code for the actual form - which is empty at first run - is on the bottom of the script. Am I wrong?
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-24 19:47

You can define the vars at the top of the script if you wish by doing something like $strName = ""; but this really just comes down to the lack of error checking in the script. As mentioned I did not write the script I just secured it up a bit.

I turn notices off on my servers as they just annoy me :)

User avatar
katip
Senior user
Senior user
Posts: 1161
Joined: 2006-12-22 07:58
Location: Istanbul

Post by katip » 2007-02-25 06:05

^DooM^ wrote:You can define the vars at the top of the script if you wish by doing something like $strName = ""; but this really just comes down to the lack of error checking in the script. As mentioned I did not write the script I just secured it up a bit.

I turn notices off on my servers as they just annoy me :)
Yep, php.ini!
; - Show all errors, except for notices
;
error_reporting = E_ALL & ~E_NOTICE | E_STRICT

Thanks for the clue Doom.
Katip
--
HMS 5.7, MariaDB 10.4.10, SA 4.0.0, ClamAV 0.103.8

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Let Users create their own accounts (Upgraded for 4.4)

Post by racman » 2007-03-09 14:44

Hi Doom,

I have made some slight changes to the email signup script for single domains. Changes are mainly to do with the form and therefore mainly cosmetic.

After the autoresponder\Vacation script issue we cleared up yesterday, I attempted to use the script in an account created by the email script but it just show a blank page. Mind you, this does not happen with account created using hMail Admin either online or offline, just happens with accounts created using this script.

Am wondering if you have encountered this before or have any idea what causes it. The updated script is as follows:

Code: Select all

<?php 

//MySQL database connection information
//MySQL connection information:
$mysql_host = "localhost"; //Host Name
$mysql_user = ""; //Username
$mysql_pass = ""; //Password
$mysql_db = "hmailserver"; //Database

//General Configuration:
$form_title = "Email Setup"; //Name for this form
$account_max = "10000000";  //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!)
$admin_notify = "1"; //1 = yes & 0 = no
$admin_email = ""; //Administrators email to send notifications)
$admin_default_activate = "0"; //1 = yes & 0 = no -> If no, the administrator has to authorise the account
$encryption = 2; //Password encryption level

$url = $_SERVER["HTTP_HOST"];
$domain = $_SERVER["HTTP_HOST"];

If (substr($domain,0,4) == "www.")
        {
                $domain = strstr($domain, ".");
                $domain = substr($domain, 1);
        }

// Protect database entries and use MD5 encryption
$strName    = addslashes( $_POST['name'] ); 
$strUser    = addslashes( $_POST['user'] ); 

$strDomain  = addslashes( "$domain" );
$strPass1   = addslashes( $_POST['pass1'] ); 
$strMD5Pass = md5( $strPass1 );

error_reporting(E_ALL ^ E_NOTICE);
//Connect to database using information from above
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
$select = mysql_select_db($mysql_db); 

        If (!$open || !$select)
        {
        echo "Unable to open database, contact your administrator!";
        }
        Else
        {
        echo "<font size=\"+1\">$form_title</font><br><br>";

        //Decide On what path to take
        Switch ($_GET['mode'])
        {
        Case "do":

        //Retrieve domain information for email application
        $q=mysql_query("SELECT * FROM `hm_domains` WHERE `domainid` = '{$strDomain}' LIMIT 1");
        While ($v=mysql_fetch_array($q)) 
        { 
        }

        //Check to see if email account exists, if not process signup
        $q2=mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$strDomain' LIMIT 1");
        $v1=mysql_num_rows($q2);
        
        If ($v1 == 1)
        { 
        echo "A subscriber with this email already exists!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
        } 
        Else 
        { 
        If (!$_POST['pass1'] || !$_POST['pass2'])
        {
        echo "You did not enter both passwords!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
        }
        ElseIf ($_POST['pass1'] <> $_POST['pass2'])
        {
        echo "The passwords entered do not match!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back.";
        }
        Else
        {
        $q3=mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$strDomain','$strUser@$strDomain','$strMD5Pass','$admin_Default_activate','0','$account_max','$encryption')") or die(mysql_error());
        }
        } 
        
        If ($q3)
        {
        If ($admin_Default_activate == 0)
        {
        echo "Your account has been created but <b>requires activation</b> by administration.";
        echo "Once your application has been approved, you will receive a confirmation message.<br><br>";
        }
        Else
        {
        echo "Your account has been created and is ready for use!<br><br>";
        echo "Username: $strUser@$strDomain<br><br>";
        echo "Webmail: <a href=\"$serv_webmail/webmail\">www.$strDomain/webmail</a><br>";
        echo "POP3: mail.$strDomain<br>";
        echo "IMAP: mail.$strDomain<br><br>";
        echo "SMTP: mail.$strDomain";
        
        $subject = "Welcome To $strDomain Email!";
        $message = "This is confirmation that your account has been created. You may now login to your account and start using it.";

        mail("{$_POST['user']}@$strDomain", $subject, $message); //Send welcome message
        }
        } 
        Else 
        { 
        // echo "<br><br>Database error, unable to add account. Please contact your administrator!";
        } 

        If ($admin_Default_activate == 0 && $admin_notIfy == 1)
        { 
        $admin_mail_subject = "Account Requires Activation!";
        $admin_mail_message = "The email account {$_POST['user']}@$strDomain has been created by {$_POST['name']} and requires administration activation!\r\n\r\nPlease login to the admin control panel to verIfy and activate user account.\r\n\r\n";
        mail($admin_email, $admin_mail_subject, $admin_mail_message);
        } 
        ElseIf ($admin_Default_activate == 1 && $admin_notIfy == 1) 
        { 
        $admin_mail_subject = "New Account Created!";
        $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
        mail($admin_email, $admin_mail_subject, $admin_mail_message);
        } 
        ElseIf ($admin_Default_activate == 1 && $admin_notIfy == 1) 
        { 
        $admin_mail_subject = "New Account Created!";
        $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
        mail($admin_email, $admin_mail_subject, $admin_mail_message);
        } 
        ElseIf ($admin_Default_activate == 0 && $admin_notIfy == 1) 
        { 
        $admin_mail_subject = "New Account Created!";
        $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!";
        mail($admin_email, $admin_mail_subject, $admin_mail_message);
        } 
        break; 
    
        Default:
        }
        }

        //Email account signup page
        echo "
        <table width=\"350\" border=\"0\" cellpadding=\"0\" cellspacing=\"2\">
        <form action=\"?mode=do\" method=\"POST\">
        <tr>
        <td>Full Name:</td><td><input type=\"text\" name=\"name\" size=\"21\"></td>
        </tr>
        <tr>
        <td>E-Mail:</td><td><input type=\"text\" name=\"user\" size=\"21\"> @
        ";
        $q2=mysql_query("SELECT * FROM `hm_domains` WHERE `domainactive` = '1' ORDER BY `domainname` DESC");
        {
        echo "$domain";
        }
        echo "
        </td>
        </tr>
        <tr>
        <td>Password:</td><td><input type=\"password\" name=\"pass1\" size=\"21\"></td>
        </tr>
        <tr>
        <td>Password:</td><td><input type=\"password\" name=\"pass2\" size=\"21\"> (For Confirmation)</td>
        </tr>
        <tr>
        <td>&nbsp;</td><td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"submit\" value=\"Submit\"></td>
        </tr>
        </form>
        ";
?>
Please let me knwo your thoughts on this.

Many thanks ...

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-03-09 15:26

I don't use that script ;D

Are any errors shown in the error log? A blank page usually signifies a parse error of some kind.

If you don't have any errors let me know and I'll take a look at the script for you.

Cheers!

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2007-03-09 17:25

Hi Doom,

Thanks for your reply. This is the error report from the php error_log:

[09-Mar-2007 15:20:55] PHP Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Unknown<br/><b>Description:</b> Unknown' in C:\Apache2\Squirrelmail\plugins\hmailserver_vacation\options.php:247
Stack trace:
#0 C:\Apache2\Squirrelmail\plugins\hmailserver_vacation\options.php(247): variant->ItemByAddress('justin@bellhosti...')
#1 C:\Apache2\Squirrelmail\plugins\hmailserver_vacation\options.php(81): GetAccountObject('justin@bellhosti...')
#2 {main}
thrown in C:\Apache2\Squirrelmail\plugins\hmailserver_vacation\options.php on line 247

Also, I have observed that any email account using the email script does not shown in the hMail Admin domains and account list. It is created in the hMail database though and can be accessed through Squirrelmail.

Thanks again for your help.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-03-09 17:44

Hmm the above error is from the vacation plugin and is a COM Exception message. The script you posted does not use the com api at all.

If I get chance tonight I will set that script up on my own system and see If i get any errors.

Cheers!

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2007-03-09 19:50

Hi Doom,

Thanks for getting back to me.

I thought this might be the case as the script does not rely on hMail compnonents. But as not everyone here is as open minded that they say, I thought I'd run it by you and avoid another riot about this issue.

Thanks again ...

gruenie
Senior user
Senior user
Posts: 299
Joined: 2004-01-23 03:25
Location: Germany, Halle

Post by gruenie » 2007-03-09 20:41

Hi pccsq1,

the dcom-error, which you posted cannot come from using that script, because - like ^DooM^ said - there is not one COM-element in it.
Nevertheless I had a look at the script you posted here and found some php- and logical errors in it.
I made some changes and hope, it is working for you now! :-)
Please make your settings in the lines 2 to 20

Here we go:

Code: Select all

<?php 
error_reporting(E_ALL & ~E_NOTICE);
//MySQL database connection information 
//MySQL connection information: 
$mysql_host = ""; //Host Name 
$mysql_user = ""; //Username 
$mysql_pass = ""; //Password 
$mysql_db = "hmailserver"; //Database 

//General Configuration: 
$form_title = "Email Setup"; //Name for this form 
$account_max = "10000000";  //Maximum size per account (1000000 = 1MB -> Do not uses spaces or commas!) 
$admin_notify = "1"; //1 = yes & 0 = no 
$admin_email = ""; //Administrators email to send notifications) 
$admin_default_activate = "0"; //1 = yes & 0 = no -> If no, the administrator has to authorise the account 
$accountisad = 0; // account is AD-account? 0 = no (default), 1 = yws;
$encryption = 2; //Password encryption level - 2 means md5;
$domain = ''; // the domain, where the account should be added too

$serv_webmail_url = ''; // full URL to the webmail-application

$url = $_SERVER["HTTP_HOST"]; 
$domain = (empty($domain))? $_SERVER["HTTP_HOST"] : $domain; 
$domain = (substr($domain,0,4) == "www.")? strstr($domain, ".") : $domain;

// Protect database entries and use MD5 encryption 
$strName    = (isset($_POST['name']))? addslashes( $_POST['name'] ) : ''; 
$strUser    = (isset($_POST['user']))? addslashes( $_POST['user'] ) : ''; 

$strDomain  = addslashes( "$domain" ); 
$strPass1   = (isset($_POST['pass1']))? addslashes( $_POST['pass1'] ) : ''; 
 
//Connect to database using information from above 
$open = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
$select = mysql_select_db($mysql_db); 

if (!$open || !$select) 
{ 
  echo "Unable to open database, contact your administrator!"; 
} else { 
  echo "<font size=\"+1\">$form_title</font><br><br>"; 
	
  if ( isset($_POST['submit']) &&  $_POST['submit'] == 'create account' )
  { 
    $domain_res = mysql_query("SELECT * FROM `hm_domains` WHERE `domainname` = '{$strDomain}' LIMIT 1"); 
   	if (!$domain_res) 
   	{
   	  die('Error while selecting data: ' . mysql_error());
	 	}
   	$domain_info = mysql_fetch_array($domain_res, MYSQL_ASSOC);

    //Check to see if email account exists, if not process signup 
    $account_res = mysql_query("SELECT * FROM `hm_accounts` WHERE `accountaddress` = '{$strUser}@$strDomain' LIMIT 1"); 
    $v1 = mysql_num_rows($account_res); 
        
    If ($v1 >= 1) 
    { 
    	echo "A subscriber with this email already exists!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back."; 
    	return false;
    } else { 
      if ( !$_POST['pass1'] || !$_POST['pass2'] ) 
      { 
      	echo "You did not enter both passwords!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back."; 
      } 
      elseif ( $_POST['pass1'] != $_POST['pass2'] ) 
      { 
      	echo "The passwords entered do not match!<br><br>Please <a href=\"javascript:history.go(-1)\">click here</a> to go back."; 
      } else { 
      	$domain_id = $domain_info['domainid'];
      	$account_pass = ($encryption == 2)? md5( $strPass1 ) : $strPass1;
      	
        $account_add = mysql_query("INSERT INTO `hm_accounts` (`accountdomainid`,`accountaddress`,`accountpassword`,`accountactive`,`accountisad`,`accountmaxsize`,`accountpwencryption`) VALUES ('$domain_id','$strUser@$strDomain','$account_pass','$admin_Default_activate','$accountisad','$account_max','$encryption')"); 
      } 
    } 
    
    if (!$account_add) 
   	{
   	  die('<br><br>Database error, unable to add account. Please contact your administrator!<br> ' . mysql_error());
	 	}
        
    If ($admin_Default_activate == 0) 
    { 
    	echo "Your account has been created but <b>requires activation</b> by administration."; 
      echo "Once your application has been approved, you will receive a confirmation message.<br><br>"; 
    } else { 
      echo "Your account has been created and is ready for use!<br><br>"; 
      echo "Username: $strUser@$strDomain<br><br>"; 
      if ( !empty($serv_webmail_url) ) echo "Webmail: <a href=\"$serv_webmail_url\">www.$strDomain/webmail</a><br>"; 
      echo "POP3: mail.$strDomain<br>"; 
      echo "IMAP: mail.$strDomain<br><br>"; 
      echo "SMTP: mail.$strDomain"; 
        
      $subject = "Welcome To $strDomain Email!"; 
      $message = "This is confirmation that your account has been created. You may now login to your account and start using it."; 

      mail("{$_POST['user']}@$strDomain", $subject, $message); //Send welcome message 
    } 
        
    if ($admin_Default_activate == 0 && $admin_notIfy == 1) 
    { 
      $admin_mail_subject = "Account Requires Activation!"; 
      $admin_mail_message = "The email account {$_POST['user']}@$strDomain has been created by {$_POST['name']} and requires administration activation!\r\n\r\nPlease login to the admin control panel to verIfy and activate user account.\r\n\r\n"; 
      mail($admin_email, $admin_mail_subject, $admin_mail_message); 
    } 
    elseif ($admin_Default_activate == 1 && $admin_notIfy == 1) 
    { 
      $admin_mail_subject = "New Account Created!"; 
      $admin_mail_message = "{$_POST['user']}@$strDomain has been created by {$_POST['name']}!"; 
      mail($admin_email, $admin_mail_subject, $admin_mail_message); 
    } 
  }
}
	
	//Email account signup page 
  echo " 
  	<table width=\"350\" border=\"0\" cellpadding=\"0\" cellspacing=\"2\"> 
    <form action=\"\" method=\"POST\"> 
    	<tr><td>Full Name:</td><td><input type=\"text\" name=\"name\" size=\"21\"></td></tr> 
      <tr><td>E-Mail:</td><td><input type=\"text\" name=\"user\" size=\"21\"> @ ".$domain."</td></tr> 
      <tr><td>Password:</td><td><input type=\"password\" name=\"pass1\" size=\"21\"></td></tr> 
      <tr><td>Password:</td><td><input type=\"password\" name=\"pass2\" size=\"21\"> (For Confirmation)</td></tr> 
      <tr><td colspan=\"2\" align=\"center\"><input type=\"submit\" name=\"submit\" value=\"create account\" style=\"width: 98%\"></td></tr> 
    </form> 
    </table>"; 
?> 
Gruenie
Last edited by gruenie on 2007-03-10 02:02, edited 1 time in total.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-03-09 20:49

gruenie, nice one :) Saved me a job...

Cheers!

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2007-03-10 00:10

Hi Gruenie,

Thanks for that update. I see the domainid was the missing element in the script. Well, it great its being updated now so other can use it.

Cheers ... :)

gruenie
Senior user
Senior user
Posts: 299
Joined: 2004-01-23 03:25
Location: Germany, Halle

Post by gruenie » 2007-03-10 01:56

Hi ^DooM^: You are welcome!

Hi pccsq1: You are welcome!

:lol:

Nevertheless we could carry the script to extremes:
1. Only send admin-mail, if a (valid) admin-mailaddress is entered
2. Add language support for the messages and form-fields
3. Add rules for the accont-name and check the input
4. Add rules for the passwords and check the input
5. Customize the outlook of the form
etc....

[Btw, I have no clue, wherefore the input-field of the full name is, because it isn't used in the script later :?: ]

Gruenie

Foolheart
New user
New user
Posts: 3
Joined: 2007-04-16 07:19
Location: Philippines
Contact:

Post by Foolheart » 2007-04-16 07:29

Hi everyone!
I'd tried the the recent script posted in this forum and it worked fine except that it could not send to the admin a notification message.
I am using the isapi module of PHP 5. Windows XP Pro, IIS 5.1, the latest hmailserver and the latest squirrelmail. I am using only an intranet, and pcs are connected per-to-peer (not client-server)

What email address should i place in admin_email? full email or username only.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-04-16 09:27

it should be full email address. gruenie rewrote the script a few messages up, maybe give that a try.

Foolheart
New user
New user
Posts: 3
Joined: 2007-04-16 07:19
Location: Philippines
Contact:

Post by Foolheart » 2007-04-18 06:18

It is the same script that I'd tested. It works now!

1. I'd change all the:

$admin_Default_activate

to

$admin_default_activate and also,

2. I'd added the email address of the sender (sendmail_from) in php.ini.

Wow! The script is amazing! Thanks to all of you there.

But I wish I could ADD the registration name of user to tthe SquirrelMail (Options >> Personal Info >>Full Name) but I don't have even the faintest idea to make or modify the php script. I only have a very little programming skills.

hytek
New user
New user
Posts: 5
Joined: 2007-05-29 22:57

Post by hytek » 2007-05-29 23:42

i cant seem to get the active switch to come on when the account is created...any ideas why this would happen? I was trying to post my script but its giving me a spam error, someone could email me i could let you look at script that would be much appreciated.

HYTEK

User avatar
danny6167
Senior user
Senior user
Posts: 472
Joined: 2007-02-07 15:24
Location: Western Australia
Contact:

Post by danny6167 » 2007-05-30 05:00

I think your spam error has to do with your low post count.
try again, 3 posts might do it.

Post Reply