PHP Mailer script to send Contact Us form email.

If the website is running on PHP Server than it’s just easy to create Form. It will only take fifteen to twenty minutes to build a form on a website. The simple static website can also be customized to have a contact us or any other form.
Let’s begin by writing a simple html code for form.

 
Note: Please remember the name that have been given to textboxes and text area. We have to use same name in PHP script. And the file must be located where our .html file is stored as we have directly specified send_form_email.php in action parameter. If you have placed somewhere else then do specify the proper path. 

Now let’s write the PHP script to send an email.
Create a file send_form_email.php

Copy the below code.

 

We need to change the $to email id to wherever you want to send an email.
As the form is submitted by the user and the form is successfully sent then we have to redirect the user to any page. So for that we have to change the header location as per requirement. Here we have redirected to our actual domain site.
Note: This will only work on PHP Server. If we try to submit the form on our local machine then we will see the php file appearing but on live server the actual mail will be sent.
 
For seeing the Demo of this application CLICK HERE.
If you were looking for something and this helped? Or if you
have any other better idea? Feel free to share with us!

Happy Coding!

Share

Leave a Reply

Your email address will not be published. Required fields are marked *