Skip to main content

How to send mail from XAMPP localhost

How To Send Mail In PHP From Localhost Using XAMPP Server

(Image Source - Google Images)

To send mail from localhost XAMPP using Gmail, configure XAMPP after installing it.
Follow the steps below for the same.

Steps to send mail from Localhost XAMPP using Gmail:

Open the XAMPP installation directory.

Go to C:\xampp\php and open the php.ini file.

Find [ smtp ] by pressing ctrl + f.
Search and pass the following values:

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = YourGmailId@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

Now, go to C:\xampp\sendmail and open the sendmail.ini file.

Find [ sendmail ] by pressing ctrl + f.
Search and pass the following values:

smtp_server=smtp.gmail.com
smtp_port=587 or 25 //use any of them
error_logfile=error.log    ( Remove if there is a semicolon ; )
debug_logfile=debug.log    Remove if there is a semicolon ; )
auth_username=YourGmailId@gmail.com
auth_password=Your-Gmail-Password
force_sender=YourGmailId@gmail.com(optional)


Here is the actual code you need to write :

Script to send mail:

<?php
$to_email = "receipientMail@gmail.com";
$subject = "Sample Mail Test From Localhost in PHP";
$body = "Hello, This is test Mail send from Localhost ( Message Part )";
$headers = "From: senderEmail";

if (mail($to_email, $subject, $body, $headers)) {
    echo "Done..! Email successfully sent to $to_email .";
} else {
    echo "Error..! Email Not Sent";
}
?>




Note: If you receive a warning message, configure the "Less secure apps" settings as shown below.
Sometimes not activating the 'less secure apps' is the main reason why the user did not receive the mail.


*Turning on 'less secure apps' settings as mailbox user*

Go to your (Google Account).
On the left navigation panel, click Security.
On the bottom of the page, in the Less secure app access panel, click Turn on access.
If you don't see this setting, your administrator might have turned off less secure app account access (check the instruction above).
Click the Save button.

Now your email will be sent successfully. Have a nice day and share your story in the comment box.

Comments

Popular posts from this blog

Responsive Google Maps

Create Responsive Google Maps on Any Website. (Image Source - Google Images) Google Maps makes it easy to insert/embed a map into your own website. However, by default, Google Maps does not provide responsive support. In my Blog, I will show you how to make your maps responsive, using just a few lines of CSS. This technique will work on any website platform. 1. Get the embed code from Google Maps Go to Google Maps. Find the area of the map you want to use on your website. Click on the "Share" link. (Image Source - Google Images) Choose "Embed map". Select the iframe code. Right-click and copy the embed code. (Image Source - Google Images) 2. Use the Google Maps Embed Code Paste the embed code on your website. It will look similar to this: <iframe src="/" width="600" height="300" frameborder="0" style="border:0" allowfullscreen></iframe> 2.1.Modify the Embed Code Add a div tag around the embed code. Use th...

Moto G8 Power Lite Released in India

Moto G8 Power Lite with 5,000 mAh battery, Helio P35 SoC released in India . The price of the Moto G8 Power Lite in India is set at Rs. 8,999 for the 4GB + 64GB solo model. (Image Source - Google Images) Motorola's Moto G8 Power Lite made its debut in India and the new phone will go on sale later this month. The phone was introduced worldwide in April. The Moto G8 Power Lite is powered by the MediaTek Helio P35 octa-core processor and has a triple rear camera setup. The phone will be offered in a single RAM and storage configuration but in two color variants. It also includes a large 5,000 mAh battery. Moto G8 Power Lite Price in India, Sale Date... Read The Tweet... 3...2...1..The #UltimatePower has been launched!🚀 Gear up to experience power like never before with ultimate battery, performance, camera, and much more, with the all-new Moto g8 power lite at just ₹8,999! Sale starts 29th May at 12 PM on @Flipkart : https://t.co/Kc3P3geEqW pic.twitter.com/nAtUy48hFD — Motorola ...

Micromax In Note 1, Micromax In 1b With MediaTek SoCs Launched in India: Price, Specifications

Micromax In Note 1 price in India starts at Rs. 10,999 , while Micromax In 1b carries a starting price of Rs. 6,999 . (Image Source - Google Images) Micromax "In" series has finally been launched in India after much anticipation and a variety of teasers.  The new series comprises the Micromax In Note 1 and Micromax In 1b that both accompany MediaTek chipsets and run on Android 10 with a “complete stock experience”, with none bloatware and ads. Micromax has also promised to supply two years of software updates on the new smartphones. The Gurugram-based company was once a pacesetter within the Indian mobile market. However, it bowed call at the growing dominance of Chinese brands including Oppo, Vivo, and Xiaomi within the country. Micromax co-founder Rahul Sharma during the virtual launch showcased the company's facility in Bhiwadi and detailed the assembly process of the new smartphones, which are being touted to be a part of the 'Make in India' initiative. (Im...