2018-11-25 Pujan Niroula 2 Minute(s) Read

How To Make Simple Contact Us form in PHP

img-secure contact us.png

Most blogs or website have contact us form in their page. That will admin to directly communicate with visitors. Usually newbie bloggers don't make contact us form in their blog. If you also don't have contact us form then you may be loosing some loyal visitor or good deal.

Let's Create Contact Us Form in PHP that will send mail to you and the person who contacted you when someone submit this form.

Simple and Secure Contact Us Form in PHP

This code have following features,

  1. Validating empty value.
  2. Validating email.
  3. Validating on Frontend and Backend.
  4. Mail to admin as well as user.

Frontend Part,

<form method="post" action="#">
<input name="name" pattern="[a-z\.' ']" required="" type="text" placeholder="Full Name" />
<input name="subject" required="" type="text" placeholder="Subject" />
<input name="email" required="" type="email" placeholder="Email" />
<textarea name="message" placeholder="Message" required=""></textarea>
<input type="submit" name="send" value="Send Message">
</form>

Let's go to backend

We will use mail() function in PHP to deliver E-mail you just have to change variable $youremail to your private email and  email to receive mail and change $publicemail to your public email from which you send mail to user.

<?php
if(isset($_POST['send']))
{
    $youremail = "youremail@mail.com.np";
    $publicemail = "your_public_email@mail.com.np";
    function input($name){
        if(isset($_POST[$name]) && !empty(trim($_POST[$name]))){
            $input = trim($_POST[$name]);
            $html = htmlspecialchars($input);
            return $html;
        } else {
            return false;
        }
    }
    if(input('name') && input('subject') && input('message') && input('email')){
        $name = input($_POST['name']);
        $subject = input($_POST['subject']);
        $message = input($_POST['message']);
        if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
            $email = $_POST['email'];
        } else {
            $err = 'Email format is not correct';
        }
    }
    else{
        $err = 'Please input all fields correctly';
    }
    if(!isset($err)){    
    //Send it to you
        $header = 'From: .'.'$name<'.$email.">\r\nReturn-path: ".$email;
        $subject = 'New Message from Contact Form';
        $send = mail($youremail, $subject, $message, $header);
    //To send thanks mail
        if ($send) {
            $header = 'From: .'.'$name<'.$publicemail.">\r\nReturn-path: ".$publicemail;
            $subject = 'Email Received Conformation';
            $message = 'We have received your message from contact us form. We will get back to you as soon as possible';
            mail($email, 'Email', $message, $header);
        }
    }
}
?>

If you want full code download it from below...

I will be happy to hear from you.

Download Attached Files: Contact Us Script in PHP.zip
Comments (50) Add New Comment
porn2024-07-19 4:56 PM

A person necessarily help to make severely articles I would state. This is the first time I frequented your website page and to this point? I surprised with the research you made to make this particular submit amazing. Fantastic process!

Reply
child porn2024-07-19 1:35 AM

This is my first time visit at here and i am actually pleassant to read everthing at one place.

Reply
slot sound effects2024-07-18 7:12 AM

5 Killer Quora Answers On Slot Sound Effects slot sound effects

Reply
Nichole2024-07-18 2:26 AM

Where Can You Find The Best Window Repair Near Information? window repair near me (Nichole)

Reply
window doctor2024-07-16 5:44 PM

Upvc Window Doctor Near Me Tools To Streamline Your Daily Life Upvc Window Doctor Near Me Trick That Everyone Should Be Able To window doctor

Reply

Very quickly this web page will be famous among all blogging and site-building viewers, due to it's nice posts

Reply
Slot Volatility2024-07-15 1:25 PM

Guide To Slot Volatility: The Intermediate Guide To Slot Volatility Slot Volatility

Reply
High RTP slots2024-07-15 10:41 AM

16 Must-Follow Facebook Pages To Slot Rtp Marketers High RTP slots

Reply
WbbdkQ2024-07-15 5:42 AM

My family members every time say that I am killing my time here at net, but I know I am getting knowledge daily by reading such pleasant articles or reviews.

Reply
child porn2024-07-15 5:05 AM

It's really a nice and helpful piece of information. I'm glad that you just shared this helpful info with us. Please stay us informed like this. Thank you for sharing.

Reply
mini key not working2024-07-15 2:19 AM

5 Laws Everybody In Replacement Key For Mini Cooper Should Be Aware Of mini key not working

Reply
UDblUl2024-07-12 8:38 PM

Fantastic post however , I was wondering if you could write a litte more on this topic? I'd be very thankful if you could elaborate a little bit more. Appreciate it!

Reply

Thank you for the good writeup. It actually was once a entertainment account it. Glance complex to more added agreeable from you! By the way, how can we be in contact?

Reply
adhd symptoms adults male2024-07-09 2:13 PM

Why Adhd In Adults Symptoms Is Still Relevant In 2023 adhd symptoms adults male

Reply
important source2024-07-08 9:37 AM

Thanks for finally writing about >[How To] Make Simple Contact Us form in PHP <Liked it!

Reply
additional hints2024-07-08 1:10 AM

Hello! I could have sworn I've visited this site before but after going through many of the articles I realized it's new to me. Anyways, I'm certainly happy I came across it and I'll be bookmarking it and checking back frequently!

Reply
Sherlyn2024-07-06 5:27 PM

White Cabin Bed Isn't As Difficult As You Think julian bowen cabin bed (Sherlyn)

Reply
emdrive.echothis.com2024-07-05 6:19 PM

The 10 Most Terrifying Things About How Do I Get A Spare Car Key how do i Get A spare car key (emdrive.echothis.com)

Reply
GYrlHH2024-07-05 2:24 PM

If you would like to get a good deal from this paragraph then you have to apply these methods to your won blog.

Reply
spam website2024-07-05 10:20 AM

Howdy would you mind sharing which blog platform you're using? I'm looking to start my own blog soon but I'm having a tough time selecting between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I'm looking for something unique. P.S Apologies for getting off-topic but I had to ask!

Reply
ZdzXdB2024-07-02 4:19 AM

A motivating discussion is worth comment. I believe that you ought to publish more about this topic, it might not be a taboo matter but generally people do not talk about these issues. To the next! Cheers!!

Reply
nIawdg2024-07-02 2:54 AM

Hello just wanted to give you a quick heads up and let you know a few of the images aren't loading properly. I'm not sure why but I think its a linking issue. I've tried it in two different internet browsers and both show the same outcome.

Reply

See What Should Mobility Scooters Be On The Pavement Tricks The Celebs Are Using should mobility scooters be on The Pavement

Reply
Couch u shaped2024-07-01 9:50 PM

The 10 Scariest Things About Couch U Shaped Couch u shaped

Reply
Opener2024-06-30 9:27 PM

11 Ways To Completely Redesign Your Car Opening Opener

Reply

8 Tips To Enhance Your Car Boot Mobility Scooter Game Collapsible Folding Mobility Scooter

Reply
pHWNGG2024-06-30 7:34 AM

I’m not that much of a internet reader to be honest but your sites really nice, keep it up! I'll go ahead and bookmark your website to come back later on. Cheers

Reply
U shaped couch2024-06-29 1:39 PM

15 Of The Most Popular Pinterest Boards Of All Time About Couch U shaped couch

Reply
Wolle-Und-Garne.De2024-06-29 12:55 PM

You'll Be Unable To Guess Coffee Machine Espresso's Benefits Coffee Machine Espresso - Wolle-Und-Garne.De -

Reply
Dick2024-06-28 2:52 PM

Who Is Cheap Cases CSGO And Why You Should Take A Look case opening - Dick -

Reply
ruslara yer yok2024-06-23 7:18 PM

I know this web site gives quality depending posts and extra stuff, is there any other web page which presents these kinds of stuff in quality?

Reply
hd porn2024-06-19 1:21 PM

Awesome! Its in fact amazing piece of writing, I have got much clear idea about from this paragraph.

Reply
dOGJkT2024-06-19 11:24 AM

My brother recommended I might like this blog. He was totally right. This post actually made my day. You cann't imagine simply how much time I had spent for this information! Thanks!

Reply
business2024-06-17 3:22 PM

Good day! Do you know if they make any plugins to help with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good success. If you know of any please share. Many thanks! You can read similar text here: blogexpander.com

Reply
hd porn2024-06-17 6:03 AM

I am regular reader, how are you everybody? This post posted at this web site is really good.

Reply
porn2024-06-14 12:43 PM

Wonderful blog! I found it while browsing on Yahoo News. Do you have any tips on how to get listed in Yahoo News? I've been trying for a while but I never seem to get there! Appreciate it

Reply
echozone.top2024-06-13 12:21 PM

Got Weblog? Here's How To Generate Income With It Echozone - echozone.top,

Reply
Blogpulse.top2024-06-13 3:22 AM

Information About Blog Writing blogpulse (Blogpulse.top)

Reply
ztnRZx2024-06-12 12:49 PM

My partner and I absolutely love your blog and find the majority of your post's to be just what I'm looking for. can you offer guest writers to write content available for you? I wouldn't mind producing a post or elaborating on a number of the subjects you write about here. Again, awesome web site!

Reply
porn2024-06-12 11:36 AM

With havin so much written content do you ever run into any problems of plagorism or copyright infringement? My website has a lot of exclusive content I've either created myself or outsourced but it seems a lot of it is popping it up all over the internet without my permission. Do you know any ways to help protect against content from being ripped off? I'd definitely appreciate it.

Reply
reletis nerev usunob emened2024-06-11 5:46 PM

Hello! I could have sworn I've visited your blog before but after looking at some of the posts I realized it's new to me. Nonetheless, I'm definitely pleased I discovered it and I'll be bookmarking it and checking back regularly!

Reply
slotcoin2024-06-09 3:12 PM

5 Ways To Drive In Order To Your Blog Or Website slotcoin

Reply
rendingnicheblog2024-06-09 9:58 AM

Convert Site Into Your Own Website rendingnicheblog

Reply
Where to escape room2024-06-09 5:12 AM

Howdy! Do you know if they make any plugins to help with SEO? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good gains. If you know of any please share. Thanks! I saw similar blog here: Escape room list

Reply
SwiuDt2024-06-09 2:16 AM

Keep on writing, great job!

Reply
coinsslot2024-06-08 6:02 PM

Six To Help Customize Blog Site coinsslot

Reply
Blog2024-06-08 5:26 PM

How To Structure A Blog That Drives Targeted Visitors To Your Website Blog

Reply
XJRRTM2024-06-08 3:36 PM

Heya! I'm at work browsing your blog from my new iphone! Just wanted to say I love reading your blog and look forward to all your posts! Keep up the superb work!

Reply
content marketing strategies2024-05-01 7:45 PM

It's The Complete Guide To Content Marketing Trends content marketing strategies

Reply
Accident Attorney st Louis2024-05-01 9:54 AM

5 Attorney For Accident Claim Projects For Any Budget Accident Attorney st Louis

Reply