After sending email, problem with displaying message

Hi all,

I’ve got a script that checks form data, sends email, all the usual stuff. The problem comes what to do after the emailing. The usual thing i do is to send the user to a new page, but this time, it isnt an option. I need to display a message on the same page (with the same url).


 // Set email, subject and style the email message
 $to = "[email protected]";
 $subject = "Some subject type thing"; 
 $headers = "From: " .$_POST['email'];
 $message .= "Name: " . $_POST['name'] . "
"; 
 $message .= "Email: " . $_POST['email'] . "
"; 
 $message .= "Phone: " . $_POST['phone'] . "
";
 if (mail($to,$subject,$message,$headers)) { 
 $endMessage == "<p>Thank You. We have recieved your request and will be in contact shortly.</p>"; // success
 } else { 
 $endMessage == "<p>Unfortunatly, your request could not be completed. Please try again.</p>"; // error
 }

This doesnt work, however, the following works and as I’ve got the right functions to display the relevent info on the page, I know its something to do with the above code.


 if (mail($to,$subject,$message,$headers)) { 
  header('Location: success.php'); // success
 } else { 
 header('Location: error.php'); // error

For your info, here is the simple function that im using to display the $endMessage


 <?php
 
 if (!isset($endMessage)) {

 ?>
<!-- some html stuff here -->
<?php }
else {
echo $endMessage;
 } 
?>

How come it doesnt work, and is there any way round it?

Any help would be appreciated

:slight_smile: