How To Post Admin Email address

I'm relatively new to PHP and I've worked all day but can't figure this out.  Your help is greatly appreciated.

I am adapting the login script from: http://php-login-script.com

I need to have the activation email sent to the admin of the site instead of the person registering.  This is because the person registering must be from the admin's organization.

I can see where the admin email must go but I can't figure out how to get it there.  

    Code excerpt Begins

      mail($_POST['email'] , "Login Activation", $message,
    "From: \"Auto-Response\" <notifications@$host>\r\n" .

      Code excerpt Ends

I was thinking I could do something like this:

SELECT user_email FROM users WHERE full_name  = 'admin'

but I can't get it to work.  

Here is the page code:
<?php 
session_start();
 
 
include ('dbc.php'); 
 
 
if ($_POST['Submit'] == 'Register')
{
   if (strlen($_POST['email']) < 5)
   {
    die ("Incorrect email. Please enter valid email address..");
    }
   if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
	{ 
	//die ("Password does not match");
	die("ERROR: Password does not match or empty..");
 
	}
	if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
	{ 
			 die("Invalid code entered. Please enter the correct code as shown in the Image");
  		} 
	$rs_duplicates = mysql_query("select id from users where user_email='$_POST[email]'");
	$duplicates = mysql_num_rows($rs_duplicates);
	
	if ($duplicates > 0)
	{	
	//die ("ERROR: User account already exists.");
	header("Location: register.php?msg=ERROR: User account already exists..");
	exit();
	}
	
		
		
	
	$md5pass = md5($_POST['pass2']);
	$activ_code = rand(1000,9999);
	$server = $_SERVER['HTTP_HOST'];
	$host = ereg_replace('www.','',$server);
	mysql_query("INSERT INTO users
	              (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`)
				  VALUES
				  ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error());
	
	$message = 
"Thank you for registering an account with $server. Here are the login details...\n\n
User Email: $_POST[email] \n
Password: $_POST[pass2] \n
Activation Code: $activ_code \n
____________________________________________
*** ACTIVATION LINK ***** \n
Activation Link: http://$server/activate.php?usr=$_POST[email]&code=$activ_code \n\n
_____________________________________________
Thank you. This is an automated response. PLEASE DO NOT REPLY.
";
 
	mail($_POST['email'] , "Login Activation", $message,
    "From: \"Auto-Response\" <notifications@$host>\r\n" .
     "X-Mailer: PHP/" . phpversion());
	unset($_SESSION['ckey']);
	echo("Registration Successful! An activation code has been sent to your email address with an activation link...");	
	
	exit;
	}	
 
?> 
<link href="styles.css" rel="stylesheet" type="text/css">
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
<p>&nbsp;</p>
<table width="65%" border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td bgcolor="d5e8f9" class="mnuheader"><strong><font size="5">Register Account</font></strong></td>
  </tr>
  <tr> 
    <td bgcolor="e5ecf9" class="forumposts"><form name="form1" method="post" action="register.php" style="padding:5px;">
        <p><br>
          Name: 
          <input name="full_name" type="text" id="full_name">
          Ex. John Wilson</p>
        <p>Email: 
          <input name="email" type="text" id="email">
          Ex. john@domain.com</p>
        <p>Password: 
          <input name="pass1" type="password" id="pass1">
          Atleast 5 chars</p>
        <p>Retype Password: 
          <input name="pass2" type="password" id="pass2">
        </p>
        <p>Country: 
          <select name="country" id="select8">
            <option value="Afghanistan">Afghanistan</option>
            <option value="USA">USA</option>
          </select>
        </p>
        <p> 
          <input name="user_code" type="text" size="10">
          <img src="pngimg.php" align="middle">&nbsp; </p>
        <p align="center"> 
          <input type="submit" name="Submit" value="Register">
        </p>
      </form></td>
  </tr>
</table>
<div align="left"></div>
</body>
</html>

Open in new window

trishahdeeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Roger BaklundConnect With a Mentor Commented:
This might be the problem:

<input type="submit" name="&nbsp;Submit&nbsp;" value="Register"

Remove &nbsp; from the name:

<input type="submit" name="Submit" value="Register"
0
 
Roger BaklundCommented:
Instead of this:

mail($_POST['email'] , "Login Activation", $message,

...you need this:

mail($admin_email , "Login Activation", $message,

You can get the $admin_email variable like this:

$res = mysql_query("select user_email from user where full_name='admin'");
$admin_email = mysql_result($res,0);
0
 
Roger BaklundCommented:
Sorry, that should be "users", not "user" : "select user_email from users ..."
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
trishahdeeAuthor Commented:
Thank you for the reply.

This is very similar to what I was already trying.  However, your solution is not working either.  I'm thinking that where I am positioning the query is wrong, but I've moved it to all different places on the page and the same thing happens, when "submit" is pushed the page "flashes" and nothing happens, ie, no record is created in db and no email is sent.

http://www.ConstructiveGrowth.org

Here is the actual page I am using with the last variation (minus the "yards" of countries in the form select field):
<?php
session_start();
 
    include "header.html";
    echo "<!-- Menu Begins -->
<div id=outer>
<ul id=point>
<li><a href=http://www.constructivegrowth.org><b>HOME</b></a></li>
<li><a href=http://www.constructivegrowth.org/members/products.php><b>PRODUCT INFO</b></a></li>
<li><a href=http://www.constructivegrowth.org/members/resources.php><b>RESOURCES</b></a></li>
<li><a href=http://www.constructivegrowth.org/contact.php><b>CONTACT INFO</b></a></li>
<li><a class=current href=http://www.constructivegrowth.org/members/register.php><b>REGISTER</b></a></li>
<li><a href=";
 
include "../rotator/rotator_joinnow.php";
 
echo "
><b>JOIN NOW</b></a></li>
<li><a href=http://www.constructivegrowth.org/members/login.php><b>LOGIN</b></a></li>
</ul>
</div>
<!-- Menu Ends -->
<div align=center>
<font size=2 color=#533B00><SCRIPT LANGUAGE=Javascript>
<!--
 
// Array of day names
var dayNames = new Array(Sunday,Monday,Tuesday,Wednesday,
				Thursday,Friday,Saturday);
 
// Array of month Names
var monthNames = new Array(
January,February,March,April,May,June,July,
August,September,October,November,December);
 
var now = new Date();
document.write(dayNames[now.getDay()] + ,  +
monthNames[now.getMonth()] +   +
now.getDate() + ,  + now.getFullYear());
 
// -->
</SCRIPT></font></div>
<table width=100% cellpadding=0 cellspacing=0 border=0>
  <tr>
    <td><img src=http://www.constructivegrowth.org/graphics/_spacer.gif width=50 height=1 alt= /></td>
    <td valign=top align=center>
<!-- Content Begins -->";
 
include ('dbc.php');
 
if ($_POST['Submit'] == 'Register')
{
   if (strlen($_POST['email']) < 5)
   {
    die ("Incorrect email. Please enter valid email address..");
    }
   if (strcmp($_POST['pass1'],$_POST['pass2']) || empty($_POST['pass1']) )
	{ 
	//die ("Password does not match");
	die("ERROR: Password does not match or empty..");
 
	}
	if (strcmp(md5($_POST['user_code']),$_SESSION['ckey']))
	{ 
			 die("Invalid code entered. Please enter the correct code as shown in the Image");
  		} 
	$rs_duplicates = mysql_query("select id from users where user_email='$_POST[email]'");
	$duplicates = mysql_num_rows($rs_duplicates);
	
	if ($duplicates > 0)
	{	
	//die ("ERROR: User account already exists.");
	echo "Location: register.php?msg=ERROR: User account already exists..";
	exit();
	}
 
	$md5pass = md5($_POST['pass2']);
	$activ_code = rand(1000,9999);
	$server = $_SERVER['HTTP_HOST'];
	$host = ereg_replace('www.','',$server);
	mysql_query("INSERT INTO users
	              (`user_email`,`user_pwd`,`country`,`joined`,`activation_code`,`full_name`)
				  VALUES
				  ('$_POST[email]','$md5pass','$_POST[country]',now(),'$activ_code','$_POST[full_name]')") or die(mysql_error());
 
$res = mysql_query("select user_email from users where full_name='admin'");
$admin_email = mysql_result($res,0);
 
	$message = 
"Thank you for registering an account with $server. Here are the login details...\n\n
User Email: $_POST[email] \n
Password: $_POST[pass2] \n
Activation Code: $activ_code \n
____________________________________________
*** ACTIVATION LINK ***** \n
Activation Link: http://$server/members/activate.php?usr=$_POST[email]&code=$activ_code \n\n
_____________________________________________
Thank you. This is an automated response. PLEASE DO NOT REPLY.
";
 
    mail($admin_email, "Login Activation", $message,
    "From: \"Auto-Response\" <admin@constructivegrowth.net>\r\n" .
     "X-Mailer: PHP/" . phpversion());
	unset($_SESSION['ckey']);
	echo("Registration Successful! An activation code has been sent to your email address with an activation link...");
 
	exit;
	}
 
?>
 
<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>
 
<p align="center"><b>Register For An Account</b></p>
 
 
<form name="form1" method="post" action="register.php" style="padding:5px;">
<table align="center" cellpadding="0" cellspacing="5" border="0">
  <tr>
    <td>Name:</td>
    <td><input name="full_name" type="text" id="full_name" size="35" style="background-image: url(../graphics/bg_gold.jpg)"></td>
    <td><font size="2" color="#777777">Ex. John Wilson</font></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input name="email" type="text" id="email" size="35" style="background-image: url(../graphics/bg_gold.jpg)"></td>
    <td><font size="2" color="#777777">Ex. john@domain.com</font></td>
  </tr>
  <tr>
    <td>Password:</td>
    <td><input name="pass1" type="password" id="pass1" size="35" style="background-image: url(../graphics/bg_gold.jpg)"></td>
    <td><font size="2" color="#777777">At least 5 characters</font></td>
  </tr>
  <tr>
    <td>Retype PW:</td>
    <td><input name="pass2" type="password" id="pass2" size="35" style="background-image: url(../graphics/bg_gold.jpg)"></td>
    <td></td>
  </tr>
  <tr>
    <td>Country:</td>
    <td><select name="country" id="select8" style="background-color: #FAF3D6">
            <option value="Afghanistan">Afghanistan</option>
          </select>
          </td>
    <td></td>
  </tr>
  <tr>
    <td>Enter Text: </td>
    <td valign="middle">
    <table cellpadding="0" cellspacing="0" border="0">
      <tr>
        <td><input name="user_code" type="text" size="17" style="background-image: url(../graphics/bg_gold.jpg)">&nbsp;&nbsp;</td>
        <td><img src="pngimg.php" align="middle"></td>
      </tr>
    </table></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="&nbsp;Submit&nbsp;" value="Register" style="background-image: url(../graphics/menu/grad.gif);padding: 2px 7px 2px 7px; font-weight: bold; background-position: bottom; background-repeat: no-repeat"></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
 
<div align="left"></div>
 
<?php
    include "footer.html";
?>

Open in new window

0
 
trishahdeeAuthor Commented:
Oh my!  Was it really that easy?  I meant to put the spaces around the Value not the Name!

I had been looking at the code for hours and never caught that.  

Thank you so much for your fresh eyes!
0
 
trishahdeeAuthor Commented:
Thanks!
0
All Courses

From novice to tech pro — start learning today.