Sending Mail in PHP:

In PHP you can also send email. To send a email through PHP you have to use “mail()” function. There are some required arguments that should be passed in mail() function.

Syntax:

mail (to, subject, message, headers, parameters)

The description of the parameters is as follows:

  • to: this is a required argument and it takes the receivers email address
  • subject: this is a required argument and here you have to specified the subject of your mail
  • message: this is also a required parameter and here you write the message which you want to send. The limitation is that in one line you can write only 70 characters. To start a new line you have to use LF(\n).
  • header: this is a optional parameter here you can add Cc and Bcc.
  • parameters: this is a optional parameter.

 Note:

This will not work on localhost it needs server

Example:

In following example we are sending simple text

 Sending HTML email:

The difference between simple email and HTML email is that when you send a simple mail it will treated as a text if you have use html tag inside it. But if you are adding the MIME version and the content type to your mail than it will treated as a HTML email.

Example:

 

Leave a Reply

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