Send an email by using gmail from localhost XAMP

Send an email by using gmail from localhost XAMP

While working on a project, I was worried about how can I check a module where I have to send regular email to my site user and visitor. Luckily, I got the solution and now I am able to send the email from my localhost XAMP. I sharing this trick with all you. Hopefully, It will be useful for all PHP developers and testers. In this example, we will learn to configure our gmail id in order to send the email.
To do this task we have to modify two files in our localhost XAMP
1.    php.ini
2.    sendmail.ini

Step 1 :

Now first open your php.ini file. For me, the location of php.ini is C:\xampp\php\php.ini
And now search the term i.e extension=php_openssl.dll,
and for enabling this job we have to remove the semicolon(;) from the beginning of this line.
Now search another term in php.ini and i.e [mail function]
and change or enter the following values:
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = “\”C:\xampp\sendmail\sendmail.exe\” -t”

And by this step, we have done with making the changes in php.ini file.

Step 2 :

Now open your sendmail.ini file and for me, the location is C:\xampp\sendmail\sendmail.ini.
Search for the same term i.e [sendmail]
and replace all code with the following code

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id@gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id@gmail.com

Congratulations, You have done. Now save these two files and restart your localhost XAMP server. And test this functionality with the following PHP code.

 

For gmail please check https://support.google.com/accounts/answer/6010255 to allow access from less secure apps.