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

WhatsApp to Start Offering Health Insurance, Micro-Pension Products in India Soon.

WhatsApp to Start Offering Health Insurance, Micro-Pension Products in India Soon. By the end of the year, WhatsApp plans to start offering affordable health insurance coverage from SBI General. (Image Source - Google Images) WhatsApp plans to start rolling out health insurance and micro-pension offers in India. India chief Abhijit Bose revealed WhatsApp's roadmap to deliver "critical livelihoods and financial services" to the country's mobile users at the Facebook Fuel for India event. The Facebook-owned company is working with SBI General to launch health insurance products, while HDFC Pension and Singapore-based firm PinBox Solutions are on board to offer micro-pension products. The new developments come alongside WhatsApp's digital payments company: WhatsApp Pay. By the end of the year, WhatsApp will begin offering affordable health insurance coverage from SBI General, Bose said during his presentation at the virtual event.  The executive also announced Whats...

How to disable WhatsApp message preview on lock screen

While iOS users have the option in the WhatsApp app to disable the preview option, Android users need to turn it off from the phone's settings section. (Image Source - Google Images) Have you ever given your phone to family members and worried that they might read a personal message on the notification panel or on the lock screen? If by chance you have experienced this, then there is a way to prevent accidents from happening. You can make sure this doesn't happen by simply disabling the WhatsApp notification or the preview message option. Note that when iOS users disable the preview option, WhatsApp only displays the sender's name and the notification text will be "Message". But this will not be the case for Android users as they will disable the WhatsApp notifications option in the phone settings. Keep reading to know more. (Image Source - Google Images) Android : How to disable WhatsApp message preview on lock screen Step 1 : Go to the Phone’s settings sectio...

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...