0

Hello so I have this contact form

HTML

<form action="mail.php" method="POST">
<p>Team Name</p> <input type="text" name="name">
<p>Your Email</p> <input type="text" name="email">
<p>Players</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="radio" name="region" value="Europe" checked>Europe
<br>
<input type="radio" name="region" value="North America">North America
<br>
<input type="submit" value="Send">
</form>

PHP

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$region = $_POST['region'];
$message = $_POST['message'];
$formcontent=" From: $name $email $region $message";
$recipient = "myemail@email.com";
$subject = "$name";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
?>

However when I click submit it auto redirects to a new page mail.php, how can I get it to stay on the same page and replace the form with thankyou or if not possible have the message at the bottom of the form below the send button.

One final thing I want to change it so when it sends the email itself the data is in this format with breaks inbetween

Team Name
Email
Region
Players

Vs what It does at the moment when I read the email I've sent

From: My Team myemail@email.com Europe Player1
Player2
Player3
Player4
Player5

1 Answers1

0

The quick answer: change your form action to <?php echo $_SERVER['PHP_SELF']; ?>.

In doing that however, you will need to detect whether the form has been submitted or not. The usual example you see in tutorials and books etc. is either to check whether $_POST['submit'] has been set (note: you'd need to add a 'name' attribute to your submit <input> tab above to make this work>; or to verify whether the page has been loaded as the result of a POST or a GET request (example below courtesy of Checking if form has been submitted - PHP):

if ($_SERVER['REQUEST_METHOD'] == 'POST')
Community
  • 1
  • 1