The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 4 of 4

Thread: After sending email, problem with displaying message

  1. #1

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

    Code:
     // 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'] . "\n"; 
     $message .= "Email: " . $_POST['email'] . "\n"; 
     $message .= "Phone: " . $_POST['phone'] . "\n";
     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.

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


  2. #2
    It doesn't work because $endMessage isn't being memorized or being submitted to the new page. Add this to the top of your script: session_start(); and set the $endMessage like this: $_SESSION['endMessage'] = 'Your text here'; and on the final pages do echo $_SESSION['endMessage'];.

  3. #3
    Ah right.

    Just had a quick try but i get some headers errors. But i dont think it will work anyway, as the form itself is in a drop down box thats generated through javascript with an onclick action on an image. When submitting the form, it of course refreshes the page and the drop down form disappears.

    I think I will have to think this through, and try and incorporate ajax into the page to prevent the page refresh and thus keeping the form in view.


  4. #4
    jwilliam's Avatar
    476
    posts
    An intellectual carrot!
    You're using the wrong operator to assign to $endMessage.

    == is for comparisons

    = is for assignment

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012