I created a contact page, however when I test it by sending an email to the website’s email (which is a gmail address) it displays a white page
here’s my php code for the contact form
<?php if (isset ($_POST['submit'])) { $name = $_POST ['name']; $mailFrom = $_POST ['email']; $message = $_POST ['message']; $mailto = "lawsafrica@gmail.com"; $headers = "From: ".$mailFrom; $txt = "You have received an e-mail from ".$name.".nn".$message; mail($mailTo, $txt, $headers); header ("Location: Contact.html?mailsend"); }
Here’s my html code (contact.html)
<section class="box1"> <h2>Contact us</h2> <div class="lines"></div> <form class="contact-form" action="contactform.php" method= "POST"> <input type= "text" class= "contact-form-text" placeholder="Your name" required> <input type= "Email" class= "contact-form-text" placeholder="Your email"required> <textarea class="contact-form-text" placeholder="Your message"required></textarea> <input type="submit" class="contact-form-btn"value="Send"> </form> </section> <section class= "box2"> <h3>Didn't find what you are looking for?</h3> <div class="lines"></div> <form class="contact-form" action="contactform.php" method= "POST" > <input type= "text" name= "name" class= "contact-form-text" placeholder="Your name"required> <input type= "Email" name= "email" class= "contact-form-text" placeholder="Your email"required> <textarea class="contact-form-text" name= "message" placeholder="Type what are you looking for"required></textarea> <input type="submit" name= "submit" class="contact-form-btn"value="Send"> </form> </section> <section class= "box3"> <h4>Become a contributor</h4> <div class="lines"></div> <form class="contact-form" action="uploads.php" method= "POST" enctype= "multipart/form-data"> <input type= "file" class= "contact-form-text" > <button type="submit" class="contact-form-btn" name= "submit">Upload</button> </form> </section>
Advertisement
Answer
It is happening because you forgot to provide name for submit button in contact.html
and in contactform.php
it will only check for post event whose name is submit isset ($_POST['submit'])
<section class="box1"> <h2>Contact us</h2> <div class="lines"></div> <form class="contact-form" action="contactform.php" method= "POST"> <input type= "text" class= "contact-form-text" placeholder="Your name" required> <input type= "Email" class= "contact-form-text" placeholder="Your email"required> <textarea class="contact-form-text" placeholder="Your message"required></textarea> <input type="submit" name="submit" class="contact-form-btn"value="Send"> </form> </section>