steviemac Posted March 24, 2007 Share Posted March 24, 2007 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. Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/ Share on other sites More sharing options...
steviemac Posted March 24, 2007 Author Share Posted March 24, 2007 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>";} } } Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214298 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 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 Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214303 Share on other sites More sharing options...
steviemac Posted March 24, 2007 Author Share Posted March 24, 2007 I like that code much better. Still only getting one reply back even thought the email address is in there more than once. Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214312 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 How do you mean? That script will only send "1" email out. Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214318 Share on other sites More sharing options...
steviemac Posted March 24, 2007 Author Share Posted March 24, 2007 If the person is in there twice with the same e-mail and two registration codes I want them to get two emails Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214358 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 ok... Dont know so much about that one. Try 2 mail() functions.. Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214367 Share on other sites More sharing options...
DeathStar Posted March 24, 2007 Share Posted March 24, 2007 I know you can use the mail() function to send to more than one person at the same time! Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214369 Share on other sites More sharing options...
steviemac Posted March 24, 2007 Author Share Posted March 24, 2007 OK, it probably will not be an issue. I just thought it was possible. Link to comment https://forums.phpfreaks.com/topic/44125-neewbe-not-sending-email-after-select-from-table/#findComment-214397 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.