# After sending email, problem with displaying message

**URL:** <https://forum.kirupa.com/t/after-sending-email-problem-with-displaying-message/297221>\
**Category:** programming\
**Created:** [September 28, 2009, 10:44am UTC](https://forum.kirupa.com/t/after-sending-email-problem-with-displaying-message/297221 "2009-09-28T10:44:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![flashstorm](https://avatars.discourse-cdn.com/v4/letter/f/41988e/32.png) [@flashstorm](https://forum.kirupa.com/u/flashstorm)\
**Post date:** [September 28, 2009, 10:44am UTC](https://forum.kirupa.com/t/after-sending-email-problem-with-displaying-message/297221/1 "2009-09-28T10:44:10Z")

</div>

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).

```auto

 // Set email, subject and style the email message
 $to = "to-someone@example.com";
 $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.

```auto

 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

```auto

 <?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

🙂
