Professional Documents
Culture Documents
How To Send Mail From Localhost XAMPP Using Gmail
How To Send Mail From Localhost XAMPP Using Gmail
Magento Extensions
XAMPP is Cross-Platform (X), Apache (A), MariaDB (M), PHP (P) and Perl (P). It is for developers to create a local
webserver for testing or deployment purposes.
As a part of testing, developers need to send emails that are always going to be there when it comes to online
businesses.
To send mail from localhost XAMPP using Gmail, con gure XAMPP after installing it. Follow the below steps for
the same.
1 SMTP=smtp.gmail.com
2 smtp_port=587
3 sendmail_from = YourGmailId@gmail.com
4 sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 1/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
1 smtp_server=smtp.gmail.com
2 smtp_port=587
3 error_logfile=error.log
4 debug_logfile=debug.log
5 auth_username=YourGmailId@gmail.com
6 auth_password=Your-Gmail-Password
7 force_sender=YourGmailId@gmail.com(optional)
Note:
Any doubts on the topic? Please mention them in the Comments section below and I’d be glad to help you out.
Thanks!
4.8
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 2/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Sanjay Jethva
Sanjay is a co-founder at Meetanshi. He is a Certi ed Magento Developer who loves creating Magento E-commerce
solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of
the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.
101 comments
Lingam raja
- Reply
Sanjay Jethva
- Reply
Hello Lingam,
It’s working here. Please do follow the steps. You are good to go.
Thank you.
viswanadhan
- Reply
Sanjay Jethva
- Reply
Hello,
It seems as if there’s a mistake in copying the code from this post.
Thanks.
Husain
- Reply
Hello,
I was getting error of port=25 but as you sggested to restart the XAMPP i did it . Now the error message is gone
but it is still failing to send email.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 3/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Sanjay Jethva
- Reply
Hello,
The problem is in sending the mail.
The root script is created.
Thank you.
Alice
- Reply
Sanjay Jethva
- Reply
Hello Alice,
Thank you.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 4/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Ankit
- Reply
Tried exactly what you mentioned. Enabled less secure apps in gmail. The remaining 5 options were also not
applicable, still getting the error:
Warning: mail(): Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port”
setting in php.ini or use ini_set() in C:xampphtdocsEC_websiteindex.php on line 8
Sanjay Jethva
- Reply
Hello Ankit,
The port is wrong. The 25th port is still being used.
I hope it helps.
Ankit
- Reply
Sir I don’t know why it is still using port 25 because I changed it to 587 in both les explicitly.
Kindly guide.
Sanjay Jethva
- Reply
Hello,
Please restart XAMPP.
Thanks.
Husain
Hello Mr Sanjay,
After following all of the above mentioned steps till your last comment “restart
XAMPP” it is now showing
Email sending failed…
It is not showing any error message .. earlier it was showing the same error
reported by Mr Ankit.
Pls Guide.
Sanjay Jethva
Hello Husain,
Please recheck the port and setting.
The issue seems to be due to port only.
Thank you.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 5/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
maklon
- Reply
Sanjay Jethva
- Reply
My pleasure!
Rayi mallesh
- Reply
Sanjay Jethva
- Reply
Hello,
There is a mistake in the sendmail_from due to which you are facing this error.
Thanks.
LAUR
- Reply
Hello, i try to send mail from localhost php in win10 and i receved this errror
Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and
“smtp_port” setting in php.ini or use ini_set() in D…
-i set in php ini
SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = user@gmail.com
sendmail_path = “\”D:\……
-and to sendmail smtp_server=smtp.gmail.com
smtp_port=4
error_log le=error.log
debug_log le=debug.log
auth_username=user@gmail.com
auth_password=pass
force_sender=user@gmail.com
– where is my error?
THANKS.
Sanjay Jethva
- Reply
Hello,
I have mentioned in the post to change the SMTP port which you have missed as it is still 25.
Thank you.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 6/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
karl
- Reply
when I run the php it says email successfully sent but I don’t receive anything in my gmail, I’ve turned on
insecure access and same happens.
Sanjay Jethva
- Reply
Hello Karl,
Please check the spam folder.
Thanks.
Farmeen
- Reply
hello sir, i did the above con guration and when i try to send a test mail from wp mail SMTP it
gives a problem and the error says “PHPMailer was able to connect to SMTP server but failed
while trying to send an email.”.
what to do .Please help!
Sanjay Jethva
- Reply
Hey,
The PHPMailer is causing the issue.
Thanks.
Vinay
- Reply
Hello sir, i applied all the steps but when i m running the script to send mail then
Sanjay Jethva
- Reply
Hello Vinay,
Please check if you have any issues from those mentioned at the end of the post.
Thanks.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 7/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Deepa
- Reply
I hv don this all steps bt i didn’t get any emails.evn I’m enable allow less app secure setting also.
Sanjay Jethva
- Reply
Hello Deepa,
Did you check the ve reasons listed at the end of the post?
Marie
- Reply
Hi,
Nice tutorial..!!!
Sanjay Jethva
- Reply
Thanks!
Amardip
- Reply
Sanjay Jethva
- Reply
Hello Amardip,
Please check this – https://drops.meetanshi.com/FTLZ2n
This is also one of the methods.
Thank you.
Robertson
- Reply
Sanjay Jethva
- Reply
Hello,
Are you using Windows or Mac?
Thank you.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 8/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Samyak
- Reply
Hey!
So I followed all the steps given. It not showing any error but the mail is not being received or sent. I will
con gured the les as per instructions.
Please help!
Sanjay Jethva
- Reply
Hello Samyak,
You might be facing one of the above listed issues. Please check it once and try again.
Thank you.
wais
- Reply
Kevin
- Reply
Thanks
Lakshmi Chandrasekar
- Reply
Sanjay Jethva
- Reply
Hello,
The issue can be due to any one of the following:
1. The mails are being sent late
2. The mail is not con gured properly
3. The port is blocked
4. Gmail does not have required permissions
5. Password is wrong
Thanks.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 9/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
sanny
- Reply
Sanjay Jethva
- Reply
teja k
- Reply
hi there, I am getting this error …Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS
command rst. z62sm5560709pf b.47 – gsmtp in C:\xampp\htdocs\form2\mail_handler.php on line 13
Something went wrong!
Sanjay Jethva
- Reply
Hello,
The issue seems to be in SMTP setup.
Please check your account in which you have setup.
Thank you.
SAIRA
- Reply
Hy..I have followed all process successfully… all DNE WITHOUT ANY ERROR..bUT NO EMAIL IS SEND BY MAIL
ACCOUNT.
Sanjay Jethva
- Reply
Hello Saira,
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 10/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Adeyemi
- Reply
Hello Sir, I did exactly as you said but I keep getting this error.
Warning: mail(): Failed to connect to mailserver at “smtp.gmail.com” port 587, verify your “SMTP” and
“smtp_port” setting in php.ini or use ini_set() in C:\xampp\htdocs\dada_php\contact_us.php on line 22
{“success”:”true”}
Sanjay Jethva
- Reply
Hello,
The issue is in SMTP port. This happens when the port is already in use.
Thank you.
ogenna
- Reply
Sanjay Jethva
- Reply
Hey,
You need to free up a port that is already being used.
Thank you.
Pushapak Kumar
- Reply
Sanjay Jethva
- Reply
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 11/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
byukusenge baraka
- Reply
Sanjay Jethva
- Reply
Hello,
Yes, you need to create a new le for it.
Thanks
Gert Kroucamp
- Reply
Sanjay Jethva
- Reply
Hey, it’s great that my tutorial helped you out. And thanks for the appreciation!
Nik Suki
- Reply
Sanjay Jethva
- Reply
happy to help
Kura
- Reply
Sanjay Jethva
- Reply
Hey! Welcome
Happy to help.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 12/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Villydger Pallarca
- Reply
Sanjay Jethva
- Reply
panos alexopoulos
- Reply
Sanjay Jethva
- Reply
Hey,
I have implemented the same solution in windows with 64 bits only. So that’s not an issue.
Please check your settings again.
Thank you.
Aditya
- Reply
sir,
i follow your instructions but there is an error
please help me
Sanjay Jethva
- Reply
Hey Aditya,
It seems that you have made a mistake of a semicolon (;)
Please refer to the above code and try again.
Thank you.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 13/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Tom
- Reply
Super helpful managed to get it working just ne! FYI for anyone else you are required to turn on less secure
apps in your gmail account and any good hosting service will have this set up as default this is just for testing on
localhost! Have fun!
Sanjay Jethva
- Reply
Hi Tom,
Thanks for the appreciation. Yeah, that’s right, this solution can be used in the local environment.
helloworld
- Reply
Warning: mail(): Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port”
setting in php.ini or use ini_set() in E:\xampp\htdocs\testing\mailTesting.php on line 8
Email sending failed…
I have checked my php.ini le and everything is in order, can you help me out? Thanks alot
Sanjay Jethva
- Reply
Hi, please re-check your con guration. Any mistake in it can cause the error.
Thanks.
ajina
- Reply
hi..
Warning: mail(): Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port”
setting in php.ini or use ini_set() in C:\xampp\htdocs\ajina\DBtoPHP\form.php on line 13
Email sending failed..
Sanjay Jethva
- Reply
Hello,
Please review your php.ini settings.
Thanks.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 14/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
dshidende
- Reply
Sanjay Jethva
- Reply
Thank you!
padmini
- Reply
Hai,
Sanjay Jethva
- Reply
Hello,
Please con gure “Less secure apps” settings as shown at
https://support.google.com/cloudidentity/answer/6260879 for proper working as mentioned in the post.
Thanks.
padmini
- Reply
i am not getting the less secure option in my gmail account.
Sanjay Jethva
- Reply
Hi again,
Please follow these steps: https://drops.meetanshi.com/wS6RSe
Thanks.
miheer
- Reply
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 15/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Walid
- Reply
Sanjay Jethva
- Reply
Hi Walid,
The address to which you are sending an Email is not available and that’s why it’s showing the error.
https://drops.meetanshi.com/emKGOZ
vanita saini
- Reply
Sanjay Jethva
- Reply
Danushan Kanagasingam
- Reply
Sanjay Jethva
- Reply
Hi Danushan,
You cannot use it for real hosting. It’s enabled by default in real hosting.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 16/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Harsh Patel
- Reply
Hey there,
the code seems to work but the actually mail was not sent.
It said mail sent succesfully but mail didnt showup in the inbox or sent box
Sanjay Jethva
- Reply
Hello Harsh,
Please con gure “Less secure apps” settings as shown at
https://support.google.com/cloudidentity/answer/6260879 to resolve your issue.
Thanks.
miltons
- Reply
Jeff
- Reply
This worked for me setting it up on two computers, but a third laptop is giving this error: Error:
[SocketException] Could not send email: Function ereg() is deprecated
even though my code isn’t using ereg() anywhere.
Sanjay Jethva
- Reply
Hello,
The problem can be with PC settings or the version of XAMPP.
Thanks.
rajarata
- Reply
Sanjay Jethva
- Reply
Hello,
This may happen if you have forgotten to place a “;” at line 8 in the script to send mail.
Thanks.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 17/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Brandon Giampa
- Reply
This still isn’t working for me. I get a success message each time, but no email.
Sanjay Jethva
- Reply
Hello Brandon,
Please con gure “Less secure apps” settings as shown at
https://support.google.com/cloudidentity/answer/6260879 to resolve your issue.
Thanks.
Do Some New
- Reply
Thanks Sanjay Sir. For this code I will always grateful to you.
Sanjay Jethva
- Reply
Happy to help
rishabh
- Reply
Thank you for making this look simple, amazing tutorial
Sanjay Jethva
- Reply
Kalpesh
- Reply
Sanjay Jethva
- Reply
Leave a reply:
Your email address will not be published.
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 18/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Name
Website
Save my name, email, and website in this browser for the next time I comment.
Post Comment
HQ
Bhavnagar
303, Shiv Elite, Madhav
Baug, Waghawadi Rd,
opp. Poojara Telecom,
Bhavnagar, Gujarat.
Ahmedabad
Branch
411, Arista Business
Space, Sindhu Bhavan
Marg, Bodakdev,
Ahmedabad, Gujarat.
Custom
er
Service
About
Contact
Us
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 19/20
12/22/2020 How To Send Mail From Localhost XAMPP Using Gmail
Help
Desk
Partner
Program
Quick
Links
Career Hiring
Free
Magento
Extensions
Best Magent
o Hosting
Best Magent
o 2 Themes
Magento
Upgrade
Service
Magento 2
Migration
Service
Client's Love
https://meetanshi.com/blog/send-mail-from-localhost-xampp-using-gmail/ 20/20