Basic HTML Contact form

Description

this is a basic html contact form that is handles with php. this code will require 4 separate files.

HTML Source Code

                        
                          <form class="contact-form" action="../contactform.php" method="post"> <!--../contactform.php is the path to the form handler, file may be in the root directory-->
	<input type="text" name="name" required="" placeholder="Name*">	
	<input type="text" name="mail" required="" placeholder="Email*">	
	<input type="text" name="subject" placeholder="Subject">	
	<textarea name="message" required="" textarea placeholder="Message*"></textarea>	
	<button type="submit" name="submit" class="btns signup">Send Message</button> <!-- this form does not work for gmail accounts-->
</form>                        
                        

PHP Source Code

                        
                          <?php

	// all the form fields below must be in the form for this code to work
if (isset($_POST['submit'])){ //isset is used to check if submit button is clicked or not
	$name = $_POST['name']; //form field defined and referenced from <form> to be included in email message
	$subject = $_POST['subject']; //form field defined and referenced from <form> to be included in email message
	$mailFrom = $_POST['mail']; //form field defined and referenced from <form> to be included in email message
	$message = $_POST['message']; //form field defined and referenced from <form> to be included in email message

	$mailTo = "create@if-media.com"; //email that the form will be sent to, does not work with gmails, mail may go to junk folder
	$headers = "From: ".$mailFrom; //users email address
	$txt = "You have received an e-mal from ".$name.".\n\n".$message; //message that will appear in the email
	
	mail($mailTo, $subject, $txt, $headers);
	header("Location: /mail-success"); //page is redirected to this location when successfull
}

?>                        
                        


Post Categories