Jump to content

Neewbe Not sending email after select from table


steviemac

Recommended Posts

First PHP is new to me.  I can write small code but for code a little more complicated I write and cut and paste either from books or the internet.

 

I want users who have forgotten their registration number to be able to input there email address and have the registration number sent to them.  My problem is if they have more than one registration number with the same email address it will only send one email from the first row it come to.  If they have 3 registration numbers in 3 rows I want them to receive all three numbers.  It would be 3 seperate emails.

 

This si the code

<?
$email=mysql_real_escape_string($email);
$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!stristr($email,"@") OR !stristr($email,".")) {
$msg="Your email address is not correct<BR>"; 
$status= "NOTOK";}


echo "<br><br>";
if($status=="OK"){  $query="SELECT email_address,registration,Contact_Person FROM bikepatrol WHERE email_address = '$email'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
$row = mysql_fetch_object($st);
$em=$row->email_address;// email is stored to a variable
if ($recs == 0) {  echo "<p align=\"center\"><font color=red><b>No E-Mail Address</b><br> Sorry your email address is not in our database .  </p>"; exit;}

        $headers4="[email protected]";         ///// Change this address within quotes to your address ///
$headers.="Reply-to: $email\n";
$headers .= "From: $headers4\n"; 
$headers .= "Errors-to: $headers4\n"; 
//$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;// for html mail un-comment this line


if(mail("$em","Your Request for registration number","$row->Contact_Person this is in response to your request for your registration number \n \nRegistration number: $row->registration \n \n Thank You \n \n Zone 5 Academy","$headers"))
{echo "<p align=\"center\"><b>THANK YOU $row->Contact_Person</b> <br>Your registration number is posted to your emil address . Please check your mail shortly. </p>";}
else{ echo " <p align\"center\"><font color=red >There is some system problem in sending your registration details to your address. Please contact Zone 5 Academy. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
} 


else {echo "<center><font face='Verdana' size='2' color=red >$msg <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
?>

 

I appreciate any help.

Just an afterthought.  I have tried to loop it and it will read all the emails in the success but will not send them.

This was eliminated

$row = mysql_fetch_object($st);

This was added

while($row = mysql_fetch_object($st)){
    
if(mail("$em","Your Request for registration number","$row->Contact_Person this is in response to your request for your registration number \n \nRegistration number: $row->registration \n \n Thank You \n \n Zone 5 Academy","$headers"))
{echo "<p align=\"center\"><b>THANK YOU $row->Contact_Person</b> <br>Your registration number is posted to your emil address . Please check your mail shortly. </p>";}
else{ echo " <p align\"center\"><font color=red >There is some system problem in sending your registration details to your address. Please contact Zone 5 Academy. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
} 
} 

Make live a bit easier!

 

make the email form liek this:

<?php
$email=mysql_real_escape_string($email);
$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!stristr($email,"@") OR !stristr($email,".")) {
$msg="Your email address is not correct<BR>"; 
$status= "NOTOK";}


echo "<br><br>";
if($status=="OK"){  $query="SELECT email_address,registration,Contact_Person FROM bikepatrol WHERE email_address = '$email'";
$st=mysql_query($query);
$recs=mysql_num_rows($st);
$row = mysql_fetch_object($st);
$em=$row->email_address;// email is stored to a variable
if ($recs == 0) {  echo "<p align=\"center\"><font color=red><b>No E-Mail Address</b><br> Sorry your email address is not in our database .  </p>"; exit;}

        $headers4="[email protected]";         ///// Change this address within quotes to your address ///
$to = "$em;
$subject = "Your Request for registration number";
$message = "$row->Contact_Person this is in response to your request for your registration number \n \nRegistration number: $row->registration \n \n Thank You \n \n Zone 5 Academy"
$headers.="Reply-to: $email\n";
$headers .= "From: $headers4\n"; 
$headers .= "Errors-to: $headers4\n"; 
//$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;// for html mail un-comment this line


if(mail($to,$subject,$message,$headers))
{echo "<p align=\"center\"><b>THANK YOU $row->Contact_Person</b> <br>Your registration number is posted to your emil address . Please check your mail shortly. </p>";}
else{ echo " <p align\"center\"><font color=red >There is some system problem in sending your registration details to your address. Please contact Zone 5 Academy. <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
} 


else {echo "<center><font face='Verdana' size='2' color=red >$msg <br><br><input type='button' value='Retry' onClick='history.go(-1)'></center></font>";}
?>

 

Easy debugging

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.