<form action="contact.php" method="post"> <label>Name:</label> <input name="Name" placeholder="Name:" type="text" required/> <label>Email:</label> <input name="Email" placeholder="Email:" type="text" required /> <label>Message:</label> <textarea name="Message" placeholder="Message:" rows="10" required></textarea> <input name="submit" type="submit" value="Submit" /> </form>
Php code to submit contact form
The 2nd step is to create a php file name it contact.php which will consist of php code to send email when the form is submitted. Define an email to which the form is send and define a subject variable and write a appropriate subject for the email. All the data of the form is submitted through POST Method and save to a variable and used a php mail function to send email. Now we will check through IF statement that the form is submitted and will show a message “Your Form is submitted successfully” and if form is fail to submit will show “Error occurred”.In this article you learn that how to create a custom contact form in php. Here is a quick review first create a form.php file and put all the necessary fields and in the 2nd step write a php code to send email.
if (isset($_POST["submit"])) { $name = $_POST["Name"]; $email = $_POST["Email"]; $message = $_POST["Message"]; $to='xyz@gmail.com'; $subject='Feedback'; $body=$name."\n".$message; $header='From: '.$email; // send mail $sent=mail($to ,$email,$message,"From: $name\n"); if($sent){ echo '<span class="error">Email Sending Failed. Please try again later.</span>'; }else{ echo '<span class="alert-success">Thank you for sending us feedback</span>'; } }
Blogger Comment
Facebook Comment