php contact form with validation and send email

php contact form with validation – Creating a basic contact form in PHP is pretty simple. PHP code to send email from contact form by the users on the website and with success message.

php contact form with validation

PHP Contact Form send an email with validation. Strip unnecessary characters (extra space, tab, newline) from the user input data (with the PHP trim() function) Validating the form submission with Multi step form wizard jquery validation Example.

Contact form database table structure

CREATE TABLE `members_tbl` (
  `contact_id` int(11) NOT NULL,
  `member_name` varchar(100) NOT NULL,
  `member_email` varchar(255) NOT NULL,
  `query_title` varchar(255) NOT NULL,
  `msgbody` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

Simple Create the contact form HTML as shown below with validation and save it with .php File extension

Step 1: Contact Form User Interface

contact-view.php
view of the php contact form with validation.



Contact Us Form



    




Step 2: PHP Contact Form Input Processing

index.php


Step 3: Send Contact Form Input Data via an Email

send_contact_mail.php

\r\n";
	if(mail($toEmail, $query_title, $msgbody, $mailHeaders)) {
	    $notification = "Your Full contact information is received successfully.";
	    $type = "success";
	}
}
require_once "contact-view.php";
?>

Don’t Miss : Contact form PHP code

Step 4: Style Code

style.css

body {
    font-family: Arial;
    width: 600px;
}

.form-container {
    background: #f1ecdf;
    border: #e2ddd2 1px solid;
    padding: 20px;
    border-radius: 2px;
}

.member-dtl {
    margin-bottom: 20px;
}

.member-dtl label {
    color: #75726c;
}

.mem-elem {
    width: 100%;
    border-radius: 2px;
    padding: 10px;
    border: #e0dfdf 1px solid;
    box-sizing: border-box;
    margin-top: 2px;
}

.span-field {
    font: Arial;
    font-size: small;
    text-decoration: none;
}

.btn-submit {
    padding: 10px 60px;
    background: #9e9a91;
    border: #8c8880 1px solid;
    color: #ffffff;
    font-size: 0.9em;
    border-radius: 2px;
    cursor: pointer;
}

.errorMsg {
    background-color: #e66262;
    border: #AA4502 1px solid;
    padding: 5px 10px;
    color: #FFFFFF;
    border-radius: 3px;
}

.successMsg {
    background-color: #9fd2a1;
    border: #91bf93 1px solid;
    padding: 5px 10px;
    color: #3d503d;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.9em;
}

.details {
    font-size: .8em;
    color: #e66262;
    letter-spacing: 2px;
    padding-left: 5px;
}

I hope you get an idea about php contact form with validation.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment