RyanSmith
RyanSmith

Reputation: 41

Submit button goes to white screen

I have made a contact form and when clicking submit with the form fully filled out the screen just goes white, The link on the page changes from contact.html to contactform.php.

<?php
    if (isset($_POST['submit'])) {
      $name = $_POST['name'];
      $subject = $_POST['subject'];
      $mailFrom = $_POST['mail'];
      $message = $_POST['message'];

      $mailTo = "[email protected]";
      $headers = "From: ".$mailFrom;
      $txt = "You have received an email from ".$name.".\n\n".$message;

      mail($mailTo, $subject, $txt, $headers);
      header("Location: index.php?mailsend");
    }
?>

<div>
  <img src="images/contact.jpg" alt="" class="background-contact">

  <div class="contact-box">
    <br>
    <p class="contact-text-tp">Email</p>

      <form class="contact-form" action="contactform.php" method="post">
        <br>
        <input type="text" name="name" placeholder="Full name">
        <br>
        <input type="text" name="mail" placeholder="Your email">
        <br>
        <input type="text" name="subject" placeholder="Subject">
        <br>
        <textarea name="message" placeholder="Message"></textarea>
        <br>
        <button type="submit" name="Submit">Send email</button>
      </form>
      <br>
    <p class="contact-text-btm">If you would like to directly email please use; <br> [email protected]</p>
  </div>

</div>

Upvotes: 1

Views: 661

Answers (3)

Pradeep Sambandam
Pradeep Sambandam

Reputation: 683

So first you need to rename the page from contact.html to contact.php and change your code like the following

<?php
    if (isset($_POST['submit'])) {
      $name = $_POST['name'];
      $subject = $_POST['subject'];
      $mailFrom = $_POST['mail'];
      $message = $_POST['message'];

      $mailTo = "[email protected]";
      $headers = "From: ".$mailFrom;
      $txt = "You have received an email from ".$name.".\n\n".$message;

      if(mail($mailTo, $subject, $txt, $headers)){
         echo 'success';
      }else{
        echo 'failure';
      }
    }
?>

<div>
  <img src="images/contact.jpg" alt="" class="background-contact">

  <div class="contact-box">
    <br>
    <p class="contact-text-tp">Email</p>

      <form class="contact-form" action="" method="post">
        <br>
        <input type="text" name="name" placeholder="Full name">
        <br>
        <input type="text" name="mail" placeholder="Your email">
        <br>
        <input type="text" name="subject" placeholder="Subject">
        <br>
        <textarea name="message" placeholder="Message"></textarea>
        <br>
        <button type="submit" name="Submit">Send email</button>
      </form>
      <br>
    <p class="contact-text-btm">If you would like to directly email please use; <br> [email protected]</p>
  </div>

</div>

Upvotes: 1

sancoLgates
sancoLgates

Reputation: 188

change your

<button type="submit" name="Submit">Send email</button>

into

<input type="submit" value="Submit" name="submit" >

please note that you need to pass value in submit to trigger the isset

Upvotes: 1

Jatin Kumar
Jatin Kumar

Reputation: 41

You can use the code on one page, just save page with ".php".

Ex : contact_form.php

Upvotes: 0

Related Questions