daveoffy Posted January 24, 2009 Share Posted January 24, 2009 I have the following code. I want to make it so if any fields are not filled in it will not send the message. $subject ="$subject"; $message="$detail"; $mail_from="$customer_mail"; $header="from: $name <$mail_from>"; $to ='my-email@site.com'; $send_contact=mail($to,$subject,$message,$header); if($name == '') { echo 'Name is missing<br>'; } if($mail_from == '') { echo 'E-Mail is missing<br>'; } if($subject == '') { echo 'Subject is missing<br>'; } if($message == '') { echo 'Message is missing<br>'; } else { echo "Message was sent"; } I have to move $send_contact=mail($to,$subject,$message,$header); to somewhere else. and make it so it dies or stops but idk how. Quote Link to comment https://forums.phpfreaks.com/topic/142246-solved-send-message-stop/ Share on other sites More sharing options...
RichardRotterdam Posted January 24, 2009 Share Posted January 24, 2009 an easy way is to create an array with error messages if the error array is empty then don't do the action for example $errorMessages=array(); if(isset($_POST['submit'])){ //check field 1 if($_POST['field1']=="") //add error to array $errorMessages[]="field1 is empty"; } //check field2 if($_POST['field2']=="") //add error to array $errorMessages[]="field2 is empty"; } } //the error array is empty i guess its safe to do something now if(sizeof($errorMessages)==0){ //Do something } Quote Link to comment https://forums.phpfreaks.com/topic/142246-solved-send-message-stop/#findComment-745215 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.