W7Code » PHP » How to Send Email using PHP

Today we will learn how to send email using php. Increasingly, these days, the email is used as a strong means of communication, sharing news, stories and among other things.

 

To send email using PHP, we will use php mail function, this function receives 4 arguments:

  1. Email address that we will send the email;
  2. The Subject of email;
  3. The message or the body of the email;
  4. The Headers, for example, where the email comes from, reply to.

 

Syntax PHP Mail Function

 

This a simple and kick way to send an email using PHP:

 

Now we will learn a styled and more complexed way to send email using php. This way user will have fields which allow user:

  • Input the email where the email come from;
  • the user to insert the email address to which you want to send the email;
  • insert the subject of the email;
  • a field that will allow user write the message of the message of the email;
  • a button to send the email.

 

For these tasks we only need create three files:

  • index.php, that will allow user set the tasks above;
  • send_email.php, which will be responsible to get the email information, and send it;
  • style.css, which will contain all the styles of our form.

 

Set our Form

In this file we set all the fields required to send the email. Create and open the file index.php.

 

Configure our Email

Now we will get all user entry data and send the email, create and open the send_email.php.

 

Style Our Form

Now we just need style our form, for that we will  create and open the file style.ccs.

 

Where we can apply this Knowledge?

 

Our final result:

send email using php

 

 

Have any Doubt? Please Feel free to expose your doubt in the comment s bellow!

Leave a Reply