PHP Code to Send Email


In today world PHP plays a vital role in website development. Using PHP you can send email to your users. You see in your inbox some mail come from which type of mail can be create using PHP. You can send mail to many users using your own PHP mail function.


Let’s come to know how to create PHP code to send Email. To clear understand of this post you should know PHP.

Step 1: Create HTML form

For sending mail using PHP you need one html form so first create your html form. Here I give you Simple Html form which contains Name field, to mail id field, Message textbox and Submit button. Take a look at the below html code.

Email form

Step 2: Create PHP Code

Already you create form in first step now you need to create PHP code for send mail. If you already know basics of PHP means it is so simple and easy to you. Here I give you simple PHP code.

In this PHP script first I create three variables to store the data collected from the html form.  After that I create script for sending mail. Please analyse the below PHP code. Here I didn’t use any validation if you need means you can validate it.

Finally you done now test you form by type name, email, message and send it. After open your Inbox you will receive the message. I hope you surely enjoy this post. Thank you