User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,631 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,168 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 424 | Replies: 8 | Solved
Reply
Join Date: Feb 2008
Location: Trinidad
Posts: 214
Reputation: maydhyam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Whiz in Training

Question Email code problem

  #1  
Mar 7th, 2008
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);
	}    
}
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Perth, Australia
Posts: 114
Reputation: Auzzie is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 14
Auzzie Auzzie is offline Offline
Junior Poster

Re: Email code problem

  #2  
Mar 7th, 2008
".'$username'." get rid of the single quotes (')
Reply With Quote  
Join Date: Feb 2008
Location: Trinidad
Posts: 214
Reputation: maydhyam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Whiz in Training

Help Re: Email code problem

  #3  
Mar 7th, 2008
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>
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
Reply With Quote  
Join Date: Jun 2007
Location: Valley Center, Kansas
Posts: 489
Reputation: kkeith29 is on a distinguished road 
Rep Power: 2
Solved Threads: 45
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Posting Pro in Training

Re: Email code problem

  #4  
Mar 7th, 2008
in the mail function you used, you forgot a variable. it should be
mail($to,$subject,$message,$headers); i think that should help.
Last edited by kkeith29 : Mar 7th, 2008 at 7:49 pm.
Reply With Quote  
Join Date: Feb 2008
Location: Trinidad
Posts: 214
Reputation: maydhyam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Whiz in Training

Re: Email code problem

  #5  
Mar 10th, 2008
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);
}
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
Reply With Quote  
Join Date: Sep 2007
Posts: 3
Reputation: etangle is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
etangle etangle is offline Offline
Newbie Poster

Re: Email code problem

  #6  
Mar 10th, 2008
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."; 
Reply With Quote  
Join Date: Feb 2008
Location: Trinidad
Posts: 214
Reputation: maydhyam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Whiz in Training

Re: Email code problem

  #7  
Mar 10th, 2008
it still doesn't display anything, even if I concactinate the headers...can anyone axplain to me why this is happening?
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
Reply With Quote  
Join Date: Nov 2007
Posts: 86
Reputation: sagedavis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
sagedavis sagedavis is offline Offline
Junior Poster in Training

Re: Email code problem

  #8  
Mar 10th, 2008
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
Reply With Quote  
Join Date: Feb 2008
Location: Trinidad
Posts: 214
Reputation: maydhyam is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
maydhyam's Avatar
maydhyam maydhyam is offline Offline
Posting Whiz in Training

Re: Email code problem

  #9  
May 16th, 2008
Great, it works now...I've even set it to send mails in HTML and not plain text.....

  1. //send email
  2. $to = "somebody@somewhere.com";
  3. $subject = "blah blah";
  4. $from = "TAIS Application";
  5.  
  6. $msg = "<html><head><title>blah blah</title></head>";
  7. $msg .= "<body><table><tr><th align='left'><font face='verdana' size='2'>Dear System Administrator,</font></th></tr>";
  8. $msg .= "<tr><th align='left'>&nbsp;</th></tr>";
  9. $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>";
  10. $msg .= "<tr><th align='left'><font face='verdana' size='2'>Kindly fix that problem.</font></th></tr>";
  11. $msg .= "<tr><th align='left'>&nbsp;</th></tr>";
  12. $msg .= "<tr><th align='left'><font face='verdana' size='2'>Regards</font></th></tr>";
  13. $msg .= "<tr><th align='left'><font face='verdana' size='2'>TAIS Administration</font></th></tr></table></body></html>";
  14.  
  15. $headers = "MIME-Version: 1.0" . "\r\n";
  16. $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
  17. $headers .= "From: ".$from."\r\nReply-To:someone@somewhere.com" . "\r\n";
  18.  
  19. $mailsend = mail("$to","$subject","$msg","$headers");
  20. echo $mailsend ? "<img src='images/emailGone.gif' /> Notification was sent." : "<img src='images/emailNotGone.png' /> Notification sending failed.";
The man who in view of gain thinks of righteousness; who in the view of danger is prepared to give up his life; and who does not forget an old agreement however far back it extends - such a man may be reckoned a complete man.
~ Confucius, The Confucian Analects
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC