How to send mail using PHP program

PHP uses SMTP to send mails. In real world applications we might need to send mails to multiple users about the new product releases or a new blog post or simply a reminder email. All these can be done using PHP. There are two ways to achieve it :
1. Configuring your php.ini file for the mailing.
2. Adding a configuration changes to the PHP script itself. Which will eventually make changes to your php.ini file.

I prefer the second way. Because it does not really make changes to your php.ini file permanently, it just uses the configuration for that instance. You can later change the configuration using another script.

First we need to provide the SMTP server details, set the port number and provide the timezone details using below line :

You can find your timezone from this Link .
PHP has a mail() function to send mails which accepts below parameters

Here we have the program :