How to Create PHP Contact Form with Email

Watch my simple tutorial video below on how to create a php contact form that will send an email from your website each time someone submit a contact form:

You can also see the code that I wrote below and use it for your own php contact form with email project:
<code>
<?php
function createContact()
{
print ‘<form action=”index.php” method=”post”>
Name: <input type=”text” name=”name” /><br />
Email:  <input type=”text” name=”email” /><br />
Phone: <input type=”text” name=”phone” /><br />
<input type=”submit” name=”submit” value=”Contact Us!” /><br />
</form>’;
}
if($_POST[‘name’] == ”)
{
createContact();
}
else
{
$name = $_POST[‘name’];
$email = $_POST[’email’];
$phone = $_POST[‘phone’];
$message = ‘Name: ‘.$name.’ Email: ‘.$email.’ Phone: ‘.$phone;
mail(’email@example.com’, ‘Contact Form email from ‘.$name, $message);
print ‘Thank You so much for your contact form’;
}
?>
</code>

You can also see the code that I wrote below and use it for your own php contact form with email project:<code><?php
function createContact(){ print ‘<form action=”index.php” method=”post”>Name: <input type=”text” name=”name” /><br />Email:  <input type=”text” name=”email” /><br />Phone: <input type=”text” name=”phone” /><br /><input type=”submit” name=”submit” value=”Contact Us!” /><br /></form>’;}

if($_POST[‘name’] == ”){ createContact();}else{ $name = $_POST[‘name’]; $email = $_POST[’email’]; $phone = $_POST[‘phone’]; $message = ‘Name: ‘.$name.’ Email: ‘.$email.’ Phone: ‘.$phone; mail(’email@example.com’, ‘Contact Form email from ‘.$name, $message); print ‘Thank You so much for your contact form’;}?></code>

Published by

Joel Gross

Joel Gross is the CEO of Coalition Technologies.