Link to home
Create AccountLog in
Avatar of BrighteyesDesign
BrighteyesDesignFlag for Afghanistan

asked on

Show sucees message on the same page as the form

I have an enquiry form that sends using a separate php script. When the forms sends a success message displays on a blank page. How can I get this message to display on the page with the actual form?

This is the part of the php script that deals with the success message

 // now we just send the message
   if (@mail($to, $subject, $message, $headers)) {
      echo "Thanks for sending your details. We will be in touch soon.";
   } else {
      echo "Failed to send";

Open in new window

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

As I can understand, the code portion you posted here belongs to the separate script which sends email and so when the message has been sent, it displays the success message in a blank page.

You should enclose the code of the separate script in a function you pass parameters to
and make this function return true or false. Based on this you should display the message in your original page.

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of BrighteyesDesign


Perfectly clear, thanks!