Send Mail using PHP

October 27, 2014 // In: PHP

Sending mail is very necessary & required feature in almost every website/web application. There are two ways to send mail using PHP. After reading this article you will be able to send mail using both methods.

  1. Built-in method
  2. Third party library like phpmailer (recommended)

I will recommend you to use phpmailer instead of built-in method. You can say, phpmailer is extended version of built-in method.


Built-in Method

mail() is built-in method which is very easy and straight forward.

mail ( $receiver_email , $subject , $message);


You can also add header information to mail.

mail ( $receiver_email , $subject , $message, $header_data);


Send Mail using PHPMailer

First you need to download phpmailer library from

To use phpmailer, First you need to include class.phpmailer.php file to your PHP file and then create PHPMailer class object, and set some required values (sender email, receiver email, subject, message etc.) and that’s it.


Attach Document (Attach any file in mail)

If you want to attach any document or file in email you just need to add

HTML Formatted Mail

If you want to send mail in HTML format you need to set IsHTML to true


That’s It, Any Question?

Ajax PHP Login with jQuery Shake effect