Jump to content


Photo

Help with Script


  • Please log in to reply
6 replies to this topic

#1 no1uno

no1uno
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 August 2006 - 01:35 AM

Hello all

I am new here (and new to PHP, but trying to learn) and would like to ask if anyone can please help me with a script.
I will need to go off the track for a second to explain what I need.

I have an email server running on my server to give my members email addresses (hmailserver) and currently I need to set them up manually.
I wanted a script so that users can create thier own account, and I found one on the hmailserver forum.

Now back to the help I need. The script (below) works fine except that I have 3 domains setup in the MySQL database and the script pulls up all 3 for ther to to choose from when I only want 1 domain available. Can someone see if the script be amended to show only one domain?

Thanks in advance.

<?php
// HMailServer New user signup Script Configuration

die("You have to configure the script first"); // <- remove this line

$dbhost = "localhost";  // host of the MySQL database
$dbuser = "root";       // Database username
$dbpassword = "";  // Your database password
$dbname = "hmail";       // the name of the database that has the hmailserver tables
$webmailurl = "http://www.yurdomainname.com/webmail/login.php"; // The url to login in the webbased mail system
$quota = "50"; // The mailbox free space

// Get the action
if (strlen($_POST["pas1"]) <= 4 && IsSet($_POST["pas1"])) {
$error .= "<centeR>Error: Your password must be longer than 4 characters</center>";
} 
else if ($_POST["pas1"] == "12345" && IsSet($_POST["pas1"])) {
$error .= "<centeR>Error: Too simple password</center>";
} 

if (IsSet($_POST["action"])) {
$action = $_POST["action"];
 } else {
$action = $_GET["action"];
}

// If there is no action, open the page for a new registration

if (!IsSet($action)) {

// Load the domain names and their ids into a variable

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM hm_domains WHERE domainactive = '1' ", $db);
$domains = "<select name=\"domain\">";
while ($row = mysql_fetch_array($result)) {
$domainid = $row['domainid'];
$domainname = $row['domainname'];
$domains .= "\n<option value=\"$domainid\">$domainname</option>";
}
$domains .= "\n</select>";
mysql_close();

echo "
<center><b>Open a new E-Mail Account</b>
<p>
(*) fields are reguired.<br>
<form action=\"\" name=\"registration\" method=\"post\">
<table border=\"0\">
<tr>
<td>* Username: <td><input type=\"text\" name=\"username\">@<td>$domains<tr>
<td>* Password: <td><input type=\"password\" name=\"pas1\"><Td><tr>
<td>* Password again: <td><input type=\"password\" name=\"pas2\"><Td><tr>
<td><td>
<input type=\"hidden\" name=\"action\" value=\"register\">

<input type=\"Submit\" value=\"Signup\"><td><tr></td></tr>
</table>";
}
else if ($action == "register") {

$domainid = $_POST["domain"];
$username = $_POST["username"];
$pas1 = $_POST["pas1"];
$pas2 = $_POST["pas2"];
//$firstname = $_POST["firstname"];
//$lastname = $_POST["lastname"];

if ($username == NULL) { 
$error = "Error: You have to enter your desired username\n";
}
if ($domainid == NULL) { 
$error .= "Error: You have to choose a domain\n<Br>";
}
if ($pas1 == NULL) { 
$error .= "Error: You have to enter your password\n<Br>";
}
if ($pas1 != $pas2) { 
$error .= "Error: Your passwords does not match\n<Br>";
}
//if ($firstname == NULL)  { 
//$error .= "Error: You have to enter your first name\n<Br>";
//}
//if ($lastname == NULL)  { 
//$error .= "Error: You have to enter your last name\n<Br>";
//}
//Check if the user exists for that domain
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM hm_domains WHERE domainid = '$domainid' ", $db);
$result = @mysql_fetch_array($result);
$address = $username . "@" . $result['domainname'];
$result = mysql_query("SELECT * FROM hm_accounts WHERE accountaddress = '$address' ", $db);
$result = @mysql_fetch_array($result);
if ($result['accountid'] != "") {
$error .= "Error: The E-Mail address $address is already registered, please coose another username or domain\n<Br>";
mysql_close();
}


if (IsSet($error)) {
echo "<Center>Oops, There was some errors, please submit the form again<br>";
echo $error;

}
else {

// Insert the new user infos
$passwd = md5($pas1);
$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbname);
$query = "INSERT INTO hm_accounts (accountaddress, accountdomainid, accountadminlevel, accountpassword, accountactive, accountisad, accountmaxsize, accountpwencryption, accountvacationmessageon) VALUES ('$address','$domainid','0','$passwd','1','0','$quota','2','0')";
mysql_query($query) or die("Error: Can not query to the database");
mysql_close();

echo "<center><B>Completed!</b> 
<br><br>
You have created an email account with us! you can use the E-Mail services
eather by pop3/imap or by using the webmail system.
<p>Please <A href=\"$webmailurl\">Login</a> to read or to send emails
<p>Thank you $username for joining us";

}
}

echo "<center><p><em><font size=\"2\">Powered by <a target=\"hmail\" href=\"http://www.hmailserver.com\">HMailServer</a> @ All rights reserved</em></font></centeR>";
?>


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 22 August 2006 - 01:36 AM

you need to read the imap section of the php manual matey.....
follow me on twitter @PHPsycho

#3 no1uno

no1uno
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 August 2006 - 01:50 AM

read the what..the where??  ???
Sorry I'm not sure of your response. I would have expected changes could be made in this part of the script:
// Load the domain names and their ids into a variable

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbname);
$result = mysql_query("SELECT * FROM hm_domains WHERE domainactive = '1' ", $db);
$domains = "<select name=\"domain\">";
while ($row = mysql_fetch_array($result)) {
$domainid = $row['domainid'];
$domainname = $row['domainname'];
$domains .= "\n<option value=\"$domainid\">$domainname</option>";
}
$domains .= "\n</select>";
mysql_close();


#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 22 August 2006 - 02:09 AM

you need to set up actual e-mail acounts as opposed to just a user registartion...

read this section of the manual http://uk.php.net/ma...en/ref.imap.php
and more specifically this page http://uk.php.net/ma...eatemailbox.php
follow me on twitter @PHPsycho

#5 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 22 August 2006 - 02:10 AM

if all you want to have as an option is one domain name, then remove the whole query to select the domain names, and the while statement that builds the vars with the data, and simply assign the domain info manually. for example, instead of

$domainid = 1; //might not even need this var if you just have 1
$domainname = 'blah';


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#6 no1uno

no1uno
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 August 2006 - 02:19 AM

Thank you to all for your advise.

Crayon Violent, that makes sense. I sort of figured it would be in that area, but as I am new to PHP I wasn't 100% sure.
I will see how it goes.

Cheers

#7 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 22 August 2006 - 02:22 AM

Sorry I totally see  where you are coming from now - I didn't look at the script just went for the jugular.... sowwie
follow me on twitter @PHPsycho




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users