Example – Send Email from Localhost in PHP


Most of the web projects have the email sending functionality. Before uploading to the live server email functionality need to be checked on the local server. But PHP mail() function will not work at the localhost. In this article, we’ll show how you can send email from localhost in PHP. Using this simple PHP script you can send email from any localhost server, like XAMPP, WAMP, or any others.

We’ll use PHPMailer for helping to send email from localhost. Not only the text email, you can send HTML email from localhost in PHP using PHPMailer. Download the PHPMailer from GitHub, also you can get it from our downloadable package.

To using Gmail SMTP server, you should need to change account access for less secure apps. Don’t worry! Just follow the below steps.

That enough!

At first, 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.


Leave A Reply

Your email address will not be published.