联系表单返回空白页面

I'm working on a little website for a game server and I have some troubles making the contact form work, when I click on submit it return a blank page and doesn't send the e-mail. Here is the code, HTML and PHP

HTML:

<form method="post" action="contact.php">
<div>
<div class="row">
<div class="6u">
<input type="text" name="senderName" id="name" placeholder="Nume" />
</div>
<div class="6u">
<input type="text" name="senderEmail" id="email" placeholder="E-mail" />
</div>
</div>
<div class="row">
<div class="6u">
<input type="text" name="senderUsername" id="name" placeholder="Username Minecraft" />
</div>
<div class="6u">
<input type="text" name="senderMethod" id="email" placeholder="Modalitate de plata (PayPal sau PaySafeCard)" />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="message" id="message" placeholder="Mesaj Optional (in caz ca vrei sa adaugi ceva)"></textarea>
</div>
</div>
<div class="row double">
<div class="12u">
<ul class="actions">
<li><input type="submit" value="Trimite" /></li>
<li><input type="reset" value="Reseteaza" class="alt" /></li>
</ul>
</div>
</div>
</div>
</form>

PHP:

if($_POST["submit"]) {
$recipient="outsidebbr@yahoo.com";
$subject="Test";
$senderName = $_POST['senderName']
$senderEmail = $_POST['senderEmail'] ;
$senderUsermame = $_POST['senderUsermame']
$senderMethod = $_POST['senderMethod']
$message = $_POST['message'] ;


mail( $recipient, $subject, "From: $senderEmail", $message);
header( "Location: form-thankyou.html" ); }
?>

Anyone can help please? Thanks!

You have a few reasons why this doesn't work:

  1. if ($_POST["submit"]) doesn't work!

    • Workaround: Add name to the submit button <input name="submit" type="submit" value="Submit" />
  2. Syntax errors missing ; in PHP.

    • Workaround: Add semicolons at the end of the lines:

      $senderName = $_POST['senderName']
      $senderUsermame = $_POST['senderUsermame']
      $senderMethod = $_POST['senderMethod']
      
  3. You are reusing the same id in multiple controls.

    • Workaround: Use different ids for multiple controls.
  4. You are not running it in a web server!

    • Workaround: Run it using a web server.

Just use:

 if($_POST) { ... }

You dont have a form field called "submit" so this will always evaluate to false. Its the form field name attribute that is used in the $_POST array. Check your console to see what you are posting.

AND even on success you will get a blank page as your are not headering anything to the browser. Put an echo in your if block.

You have syntax error in your php code, you need to add ";" in end of string declaration

$senderName = $_POST['senderName']
$senderUsermame = $_POST['senderUsermame']
$senderMethod = $_POST['senderMethod']

For development purposes (only for development) you can errors reporting to debug you code:

ini_set("display_errors", 1);
error_reporting(E_ALL ^ (E_NOTICE));

Give name to the submit button

<li><input type="submit" value="Trimite" name="submit" /></li>