Feb
8
2017

How to Send Email from Localhost in PHP

In this tutorial i will discuss how to send email from from localhost (XAMPP, WAMP, LAMP) in php. When you install XAMPP, WAMP, LAMP in your local system APACHE won’t default setup for SMTP server. So PHP mail() function will not work unless you set up SMTP server.

How to Send Email from Localhost in PHP
Download Code
Step 1 :

1. Login to your google account.
2. Go to the Less secure apps settings page – https://www.google.com/settings/security/lesssecureapps
3. From Access for less secure apps section, select Turn on.

Step 2 :

Now include PHPMailerAutoload.php file in your script and create an instance of PHPMailer class.
Set your Google email address as SMTP username and password as SMTP password.
Insert the HTML email body content into the $bodyContent variable.

You can send multiple attachments with email by using the following code.

Great ! You can now send email from localhost before production. Other best part is you do not have to change any php configuration file.

I hope you understand very well How to Send Email from Localhost in PHP.
If you have any query regarding our tutorial How to Send Email from Localhost in PHP then you can comment.

About the Author: Sanjeev Kumar

Experienced PHP Web Developer and founder of www.codemarts.com. Expert in Codeigniter (MVC), WordPress, JSON, jQuery & HTML5.

1 Comment+ Add Comment

  • thank you for sharing this informative blog.. this blog really helpful for everyone.. explanation are clear so easy to understand… I got more useful information from this blog

    php training course contents

Leave a comment