Hi,
Can anyone tell me what is wrong with my code? I am trying to have an email sent to the email addy hardcoded informing the the email receiver that the info was sent into the DB...and when I do add a user, no email was sent...only the registration data was added to the DB...

function addNewOperator($Badge, $fn, $ln, $username, $password)
{
   global $conn;
   $f=strtoupper(substr ( $fn, 0 , 1 ));
   $l=strtoupper(substr ( $ln, 0 , 1 ));
   $initials=$f."".$l;
   $al="NULL";
   $q = "INSERT INTO Operators (EmployeeID,LastName,FirstName,Initials,username,password,accessLevel) VALUES ('$Badge','$ln','$fn','$initials','$username', '$password','$al')";   
   return mysql_query($q,$conn);  
      
   //sends an email notification to administrator about new account registered.
	if($al=="NULL")
	{
		$mailheaders = "From : ".'$username'."\n";
		$mailheaders = "Goodday, \n I just registered in the your Website.\n Awaiting your finalization.";
		$to = "someone@somewhere.com";
		$subject = "New Account";
	
		mail($to,$subject,$mailheaders);
	}    
}

I did that, but it didn't make any difference...:'(

here's the code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/TAIStemplate.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Operator Assisted Calls</title>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--
.style1 {
	color: #FFFFFF;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-style: normal;
	font-weight: lighter;
	font-size: 20px;
}
body {
	background-color: #FFFFFF;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.style2 {
	font-size: 20px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style3 {
	font-size: 18px;
	font-weight: bold;
	color:#0000CC
}
-->
</style>
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
body {
	background-color: #CCFFFF;
}
.style4 {color: #000000}
.style17 {
	color:#FF0000;
	font-size:16px;
	font-family: Times New Roman, Times, serif;
	text-transform:uppercase;
}
-->
</style>
<!-- InstanceEndEditable -->

</head>

<body>
<table width="700" height="244" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">
  <tr bordercolor="#FF0000">
    <th width="794" height="136" bordercolor="#FFFFFF" scope="col"><img src="/images/Operator_Banner.jpg" alt="Web page banner" width="791" height="136" longdesc="/images/Operator_Banner.jpg" /></th>
  </tr>
  <tr bordercolor="#0000FF" bgcolor="#0000FF">
    <td height="107" bordercolor="#FFFFFF" bgcolor="#FFFFFF"><div align="center">
      <div align="center"><img src="/images/menu.jpg" alt="menu" width="775" height="30" border="0" usemap="#Map" /></div>
      <table width="775" border="0">
        <tr bordercolor="#99CCFF">
          <td>&nbsp;</td>
        </tr>

        <!-- InstanceBeginEditable name="body" -->
		<script src="functions.js" type="text/javascript" language="javascript">
			
		</script>
        <?
session_start(); 
include("./connect.php");
/**
 * Returns true if the username has been taken
 * by another user, false otherwise.
 */
function usernameTaken($username)
{
   global $conn;
   if(!get_magic_quotes_gpc())
   {
      $username = addslashes($username);
   }
   $q = "select EmployeeID from Operators where username = '$username'";
   $result = mysql_query($q,$conn);
   $row=mysql_fetch_array($result);
   $_POST['badge_num']=trim($_POST['badge_num']);
   if($row['EmployeeID']==$_POST['badge_num'])
   	return true;
   else return false;
}
/**
 * Inserts the given (username, password) pair
 * into the database. Returns true on success,
 * false otherwise.
 */
function addNewOperator($Badge, $fn, $ln, $username, $password)
{
   global $conn;
   $f=strtoupper(substr ( $fn, 0 , 1 ));
   $l=strtoupper(substr ( $ln, 0 , 1 ));
   $initials=$f."".$l;
   $al="NULL";
   $q = "INSERT INTO Operators (EmployeeID,LastName,FirstName,Initials,username,password,accessLevel) VALUES ('$Badge','$ln','$fn','$initials','$username', '$password','$al')";   
   return mysql_query($q,$conn);  
      
   //sends an email notification to administrator about new account registered.
	if($al=="NULL")
	{
		$mailheaders = "From : ".$username."\n";
		$mailheaders = "Goodday, \n I just registered in your Web Application.\n Awaiting your finalization.";
		$to = "someone@somewhere.com";
		$subject = "New Account";
	
		mail($to,$subject,$mailheaders);
	}
    
}


/**
 * Displays the appropriate message to the user
 * after the registration attempt. It displays a 
 * success or failure status depending on a
 * session variable set during registration.
 */
function displayStatus()
{
   $uname = $_SESSION['reguname'];
   //echo("This is reguname session".$uname);
   if($_SESSION['regresult'])
   {
		?>
		<tr>
		<h1>Successful</h1>
		<p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database.</p>
		<p>The System Administrator would contact you when your account have been finalised. You may now proceed to the home page.<a href="/index.php" title="Home">Home</a>.</p>
		</tr>

		<?
   }	
   else
   {
		?>
		<tr>
		<h1>Registration Failed</h1>
		<p>An error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>
Please try again at a later time.</p>
		</tr>

		<?
   }
   unset($_SESSION['reguname']);
   unset($_SESSION['registered']);
   unset($_SESSION['regresult']);
}

if(isset($_SESSION['registered']))
{
	/**
	 * This is the page that will be displayed after the
	 * registration has been attempted.
	 */
	?>
	<? displayStatus(); ?>
	<?
   return;
}

/**
 * Determines whether or not to show to sign-up form
 * based on whether the form has been submitted, if it
 * has, check the database for consistency and create
 * the new account.
 */
if(isset($_POST['Submit']))
{

	/* Make sure all fields were entered */
   if((!$_POST['uname']) || (!$_POST['passwd'])||(!$_POST['badge_num'])||(!$_POST['fname'])||(!$_POST['lname'])||(!$_POST['passwd_again']))
   {
   		echo '<tr><td><h1>ALL FIELDS ARE REQUIRED</h1></td></tr>';
      	die();
   }

   /* Spruce up username, check length */
   /*$_POST['uname'] = trim($_POST['uname']);
   if(strlen($_POST['uname']) > 30)
   {
   		echo '<tr><td><h1>Sorry, the username is longer than 30 characters, please shorten it.</h1></td></tr>';
		die();
   }*/

   /* Check if username is already in use */
   if(usernameTaken($_POST['uname']))
   {
	  echo"<tr><td><h2>The username: $_POST[uname] is already registered.</h2></td></tr>";
	  echo('<tr><td>You may proceed to <a href="/reglog.php" title="Login">log in</a></td></tr>');
      die();
   }
	if($_POST['passwd'] != $_POST['passwd_again'])
	{
		echo"<tr><td><h2>The Passwords do not match. Please confirm the correct password</h2></td><tr>";
		die();
	}
   /* Add the new account to the database */
   $md5pass = md5($_POST['passwd']);
   $_SESSION['reguname'] = $_POST['uname'];
   $_SESSION['regresult'] = addNewOperator($_POST['badge_num'],$_POST['fname'],$_POST['lname'],$_POST['uname'], $md5pass);
   $_SESSION['registered'] = true;

   echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
   return;
}
else
{
	/**
	 * This is the page with the sign-up form, the names
	 * of the input fields are important and should not
	 * be changed.
	 */

	?>
	<tr>
		<td>
			<form name="reg"  id="reg" action="<?=$HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
			<table width="784" border="0" align="center" cellpadding="1" cellspacing="0" bordercolor="#FFFFFF" id="register">
			  <tr>
			    <td>
					<h1 align="left" class="style3"><span class="style4">Enter your Badge Number:*</span></h1>
				</td>
			    <td width="534" align="left">
					<input name="badge_num" id="badge_num" type="text" size="6" maxlength="6" onkeydown="if(event.keyCode==13) event.keyCode=9;" onblur="return badgeCheck('badge_num','fname','lname')" tabindex="1" /><span id="badgeerror" class="style17" ></span>
				</td>
			  </tr>
		  	  <tr>
			    <td><h1 align="left" class="style3"><span class="style4">Enter your First Name:</span></h1>
				</td>
			    <td width="534" align="left"><input name="fname" id="fname" onkeydown="if(event.keyCode==13) event.keyCode=9;" type="text" size="30" />
				</td>
			  </tr>
			  <tr>
			    <td><h1 align="left" class="style3"><span class="style4">Enter your Last Name:</span></h1>
				</td>
			    <td width="534" align="left"><input name="lname" id="lname" type="text" size="30" onkeydown="if(event.keyCode==13) event.keyCode=9;"/>
				</td>
			  </tr>
			  <tr>
			    <td><h1 align="left" class="style3"><span class="style4">Enter your Username:</span></h1>
				</td>
			    <td width="534" align="left"><input name="uname" id="uname" type="text" size="30" onkeydown="if(event.keyCode==13) event.keyCode=9;" maxlength="30"/>
				</td>
			  </tr>
			  <tr>
			    <td><h1 align="left" class="style3"><span class="style4">Enter your Password:*</span></h1>
				</td>
			    <td width="534" align="left"><input name="passwd" id="passwd" type="password" tabindex="2" size="30" onkeydown="if(event.keyCode==13) event.keyCode=9;" maxlength="30"/>
				</td>
			  </tr>
			  <tr>
			    <td><h1 align="left" class="style3"><span class="style4">Confirm Password:*</span></h1>
				</td>
			    <td width="534" align="left"><input name="passwd_again" tabindex="3" id="passwd_again" type="password" size="30" maxlength="30" onkeydown="if(event.keyCode==13) event.keyCode=9;"/>
				</td>
			  </tr>
			</table>
		<p align="left">
		<input type="submit" name="Submit" value="Submit" tabindex="-1" />
	</p>
<!--<tr><td>
<p>
<span id="txtHint"></span>
</p>
</td></tr>-->
</form>

</td>
</tr>

<? } ?>

        <!-- InstanceEndEditable -->
      </table>
    </div></td>
  </tr>
</table>

<map name="Map" id="Map">
<area shape="rect" coords="4,5,101,23" href="http://corpweb/ittweb04/Default.htm" target="_self" />
<area shape="rect" coords="121,4,308,22" href="/reglog.php" target="_self" />
<area shape="rect" coords="325,4,516,23" href="/cr.bat" />
<area shape="rect" coords="539,4,628,22" href="#" />
<area shape="rect" coords="642,4,769,22" href="http://corpweb/ittweb04/Policy.htm" target="_blank" />
</map>
</body>
<!-- InstanceEnd --></html>

in the mail function you used, you forgot a variable. it should be
mail($to,$subject,$message,$headers); i think that should help.

Well I have a bigger problem, today when I tried to register, the page is blank, but as soon as I comment off this chunk of code, the page displays as normal...

//sends an email notification to administrator about new account registered.
if($al=="NULL")
{
    $mailheaders = "From : ".'$username'."\n";
    $mailheaders = "Goodday, \n I just registered in the your Website.\n Awaiting your finalization.";
    $to = "someone@somewhere.com";
    $subject = "New Account";

    mail($to,$subject,$mailheaders);
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

seems you are not concatinating $mailheaders var, try this:

$mailheaders = "From : ".'$username'."\n";
$mailheaders .= "Goodday, \n I just registered in the your Website.\n Awaiting your finalization.";

it still doesn't display anything, even if I concactinate the headers...can anyone axplain to me why this is happening?

You don't have a message in there. This could be stopping your email.

you posted that long code then later came back with another issue that you are having with the blank page.. I am assuming that you have made some changes between the first long code and now.

It could be that with those changes you forgot to close something out, a missing quote mark or a missing function close SOMETIMES can cause this problem (especially if you have turned off error reporting).

is it possible that you are sending the email but once sent it is returning nothing, or doing nothing, so, you get a blank page, and that, you are not seeing the result of recieving the email because you have not added a message to the email to begin with so the server is kicking your email back?

Something that should help you in trouble shooting this issue is to create just a simple form for emailing and get that working.... run your tests and so on.
Take everything regarding email out of this project all together and get it to do everything that you want it to do on it's own.

This way, you know that both work seperatly. Then you can try to put them back together.
Sage

Great, it works now...I've even set it to send mails in HTML and not plain text.....

//send email     
		$to = "somebody@somewhere.com";
		$subject = "blah blah";
		$from = "TAIS Application";

		$msg  = "<html><head><title>blah blah</title></head>";
		$msg .= "<body><table><tr><th align='left'><font face='verdana' size='2'>Dear System Administrator,</font></th></tr>";
		$msg .= "<tr><th align='left'>&nbsp;</th></tr>";
		$msg .= "<tr><th align='left'><font face='verdana' size='2'>User <font color='red'>".$myrow['FirstName']." ".$myrow['LastName']."</font> (<font color='red'>".$empNo."</font>) has blah blah.</font></th></tr>";		
		$msg .= "<tr><th align='left'><font face='verdana' size='2'>Kindly fix that problem.</font></th></tr>";	
		$msg .= "<tr><th align='left'>&nbsp;</th></tr>";
		$msg .= "<tr><th align='left'><font face='verdana' size='2'>Regards</font></th></tr>";	
		$msg .= "<tr><th align='left'><font face='verdana' size='2'>TAIS Administration</font></th></tr></table></body></html>";			

		$headers  = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
		$headers .= "From: ".$from."\r\nReply-To:someone@somewhere.com" . "\r\n";
			
    	$mailsend = mail("$to","$subject","$msg","$headers");
		echo $mailsend ? "<img src='images/emailGone.gif' /> Notification was sent." : "<img src='images/emailNotGone.png' /> Notification sending failed.";
This question has already been answered. Start a new discussion instead.