Run PHP Code After Form Submission And Redirect

Jordan U.

I want to run some php code after a form is submitted on my website. It redirects to another page to email the information, then uses header() to return to the previous page. What I would like to happen is to load a small message that shows that the message was sent successfully, but I'm not sure how to do this after being redirected from another page. I'm hoping to use php or jquery to accomplish this, and I'm including the code I'm using below. I have tried to use the session_start function to do this, but the echoed text remains on the page after the user leaves.

<form method="post" action="mail.php">
<tr>
<td class="label">Name:</td>
<td class="input"><input type="text" maxlength="40" name="name" pattern="[a-zA-Z0-9]+" title="Please enter your name." required></td>
</tr>
<tr>
<td class="label">Email:</td>
<td class="input"><input type="email" maxlength="24" name="email" title="Please enter an email address." required></td>
</tr>
<tr>
<td class="label">Subject:</td>
<td class="input"><input type="text" maxlength="24" name="subject" title="Please enter a subject." required></td>
</tr>
<tr>
<td class="label">Message:</td>
<td class="input"><textarea rows="9" maxlength="1000" name="message" title="Please enter a message." required></textarea></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Submit">
</td>
</tr>
</form>

<?php
$to = "[email protected]";
$subject = "Message From Your Website: ".trim(htmlspecialchars($_POST["subject"]));
$message = trim(htmlspecialchars($_POST["message"]));
$headers = "Reply To: ".trim(htmlspecialchars($_POST["email"]))."" ."\r\n". "From: " .trim(htmlspecialchars($_POST["name"]))."";
mail($to,$subject,$message,$headers);
header("Location: index.php#contact");
?>
Aaria Carter-Weir

Easy.

header("Location: index.php?thankyou#contact");

Then do a conditional for isset($_GET['thankyou']) and print out a message.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do I see a blank screen after form submission in PHP?

From Dev

How to redirect page on form submission

From Dev

Cannot redirect after form submission

From Dev

Clear the form field after successful submission of php form

From Dev

Redirect after AJAX form submission

From Dev

php return to page after form submission

From Dev

PHP after form submission disappears instead of redirecting via header location

From Dev

Undefined index errors in PHP form submission code

From Dev

How to show a success message after PHP form submission?

From Dev

Django redirect to index view with correct URL after form submission

From Dev

Should I use a 301, 302, or 303 redirect after form submission?

From Dev

Keep form data inside the field after submission using php

From Dev

Redirect after form submitted php

From Dev

how to clear form using php PDO after successful submission

From Dev

RoR: form_tag, redirect after submission

From Dev

redirect straight after form submission

From Dev

Redirect after AJAX form submission

From Dev

php return to page after form submission

From Dev

get redirect_to and flash notices to work after ajax form submission

From Dev

Redirect Url After Form Submission

From Dev

Keeping values selected after form submission with php

From Dev

Not able to redirect a Django form after submission

From Dev

jquery ajax requests are not responding on the new tab after the php form submission

From Dev

Can't get rid of blank php page after submission form

From Dev

How to redirect to new html page after form submission in Apps script

From Dev

Run script and php after form submission

From Dev

Trigger a redirect to a page on form submission after three incorrect attempts in Javascript

From Dev

AJAX and php form inadvertently refreshes again after submission

From Dev

PHP - Access Code Form Submission not working?

Related Related

  1. 1

    Why do I see a blank screen after form submission in PHP?

  2. 2

    How to redirect page on form submission

  3. 3

    Cannot redirect after form submission

  4. 4

    Clear the form field after successful submission of php form

  5. 5

    Redirect after AJAX form submission

  6. 6

    php return to page after form submission

  7. 7

    PHP after form submission disappears instead of redirecting via header location

  8. 8

    Undefined index errors in PHP form submission code

  9. 9

    How to show a success message after PHP form submission?

  10. 10

    Django redirect to index view with correct URL after form submission

  11. 11

    Should I use a 301, 302, or 303 redirect after form submission?

  12. 12

    Keep form data inside the field after submission using php

  13. 13

    Redirect after form submitted php

  14. 14

    how to clear form using php PDO after successful submission

  15. 15

    RoR: form_tag, redirect after submission

  16. 16

    redirect straight after form submission

  17. 17

    Redirect after AJAX form submission

  18. 18

    php return to page after form submission

  19. 19

    get redirect_to and flash notices to work after ajax form submission

  20. 20

    Redirect Url After Form Submission

  21. 21

    Keeping values selected after form submission with php

  22. 22

    Not able to redirect a Django form after submission

  23. 23

    jquery ajax requests are not responding on the new tab after the php form submission

  24. 24

    Can't get rid of blank php page after submission form

  25. 25

    How to redirect to new html page after form submission in Apps script

  26. 26

    Run script and php after form submission

  27. 27

    Trigger a redirect to a page on form submission after three incorrect attempts in Javascript

  28. 28

    AJAX and php form inadvertently refreshes again after submission

  29. 29

    PHP - Access Code Form Submission not working?

HotTag

Archive