Jump to content

[SOLVED] send message stop


daveoffy

Recommended Posts

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 ='[email protected]';
$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.

Link to comment
https://forums.phpfreaks.com/topic/142246-solved-send-message-stop/
Share on other sites

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
}

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.