PHP Contact Form Send Email

PHP contact us form send email with validation; Through this tutorial, you will learn how to make contact form send email in PHP with validation.

And as well as, you can use and download free source code of the PHP contact us form send email with validation.

PHP Contact us Form Send Email with Validation

Use the following steps to make a contact form send email in PHP with validation:

  • Step 1 – Create Contact Form in PHP
  • Step 2 – Create Script To Send Email in PHP

Step 1 – Create Contact Form in PHP

In this step, you need to create contact send email form with validation and add the following code to your contact-form.php file:

<!doctype html>

  <meta charset="utf-8">
  <title>Contact Form in PHP</title>
  <link rel="stylesheet" href="">
    .container {
      max-width: 500px;
      margin: 50px auto;
      text-align: left;
      font-family: sans-serif;

    form {
      border: 1px solid #1A33FF;
      background: #ecf5fc;
      padding: 40px 50px 45px;

    .form-control:focus {
      border-color: #000;
      box-shadow: none;

    label {
      font-weight: 600;
    .error {
      color: red;
      font-weight: 400;
      display: block;
      padding: 6px 0;
      font-size: 14px;

    .form-control.error {
      border-color: red;
      padding: .375rem .75rem;


  <div class="container mt-5">

    <!-- Contact form -->
    <form action="send-mail.php" name="contactForm" method="post" enctype="multipart/form-data">
      <div class="form-group">
        <input type="text" class="form-control" name="name" id="name">

      <div class="form-group">
        <input type="email" class="form-control" name="email" id="email">

      <div class="form-group">
        <input type="text" class="form-control" name="phone" id="phone">

      <div class="form-group">
        <input type="text" class="form-control" name="subject" id="subject">

      <div class="form-group">
        <textarea class="form-control" name="message" id="message" rows="4"></textarea>

      <input type="submit" name="send" value="Send" class="btn btn-dark btn-block">



Step 2 – Create Script To Send Email in PHP

Create one file name send-mail.php and add the following code into it:


      if(!empty($_POST["send"])) {
        $name = $_POST["name"];
        $email = $_POST["email"];
        $phone = $_POST["phone"];
        $subject = $_POST["subject"];
        $message = $_POST["message"];

        // Recipient email
        $toMail = "[email protected]";
        // Build email header
        $header = "From: " . $name . "<". $email .">\r\n";

        // Send email
        if(mail($toMail, $subject, $message, $header)) {

            echo "Mail send";

        } else {

            echo "Mail not send";

The above-given code will use to send mail when the user submits a contact form in PHP.


In this tutorial, you have learned how to create a contact form send email with validation in PHP.

Recommended PHP Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet and extranet products.



Developer Center




[email protected]