How to send email from localhost(XAMPP or WAMP) in PHP in Windows
Hello Friends,
Whenever you works in local server (XAMPP or WAMP) for developing any email functionality in website, than you might be wonder that why email is not going from localhost(XAMPP or WAMP) in windows environment. Well, i faced the same situation and in this case i can help you. Below is the error you might get when working with email.
"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"
Here i am showing you the way,how to send email from XAMPP or WAMP (localhost) in PHP in Windows.
1) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMPP server.
2) Search [mail function] in the php.ini file.
You can find like below.
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
sendmail_from = me@localhost.com
Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25.
Change sendmail_from from me@localhost.com to your domain email address which will be used as from address..
So for me, it will become like this.
[mail function]
; For Win32 only.
SMTP = smtp.programmingfacts.com
smtp_port = 25
; For Win32 only.
sendmail_from = info@programmingfacts.com
3) Restart the XAMPP or WAMP(apache server) so that changes will start working.
4) Now try to send the mail using the mail() function ,
mail("raxit4u2@gmail.com","Success","Thanks, that works");
Well that's all, now mail is sent to "raxit4u2@gmail.com" from the localhost.
To know more about programming,JavaScript issues,jQuery,Expression Engine,MYSQL database and Open-source, enter your email address below. We will send you free tutorials.






I am
about 1 year ago
Hi rakshit,
Really cool post.. Do continue your posting !
All the best.
about 1 year ago
Hi rakshit,
Really cool post.. Do continue your posting !
All the best.
about 1 year ago
What about authentication from my server? I am using Google Apps for my domain and it returns a error: Failed to connect to mailserver at "smtp.mydomain.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini
about 1 year ago
What about authentication from my server? I am using Google Apps for my domain and it returns a error: Failed to connect to mailserver at "smtp.mydomain.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini
about 1 year ago
Thanks venke.
about 1 year ago
Thanks venke.
about 1 year ago
@Yateen — You need to set smtp.yoursitename.com for SMTP..
For e.g.. i have set smtp.programmingfacts.com.
about 1 year ago
@Yateen — You need to set smtp.yoursitename.com for SMTP..
For e.g.. i have set smtp.programmingfacts.com.
about 1 year ago
good and easy way, your teaching approach is very good..
about 1 year ago
good and easy way, your teaching approach is very good..
about 1 year ago
i do not have domain name of my site can
i send mail or what about if i have password
about 1 year ago
@saransh , you must have smtp details in order to send mail from local server.
about 1 year ago
@saransh , you must have smtp details in order to send mail from local server.
about 1 year ago
Thanks Rakshit for the info.
One query-
even if i set say sendmail_from = info@programmingfacts.com and i used 'from' email id some thing else in php mail() function
will email work properly? or there will be issue like spam
about 1 year ago
Thanks Rakshit for the info.
One query-
even if i set say sendmail_from = info@programmingfacts.com and i used 'from' email id some thing else in php mail() function
will email work properly? or there will be issue like spam
about 1 year ago
@avinash – See sendmail_from is not enough for sending mail from local. As i said earlier you must have a SMTP detail in order to send the mail from local server. If you have any hosting than you must have SMTP details.
about 1 year ago
@avinash – See sendmail_from is not enough for sending mail from local. As i said earlier you must have a SMTP detail in order to send the mail from local server. If you have any hosting than you must have SMTP details.
about 1 year ago
Thanks Rakshit for prompt reply.
Surly I should do all settings,
Say I have done with all settings, also done with setting some thing like sendmail_from = info@programmingfacts.com and then using some other email id as ‘from’ in php mail function what issues do u think could be raised.
Also person receiving email thru this will always be able to see sendmail_from = info@programmingfacts.com from email details
about 1 year ago
Thanks Rakshit for prompt reply.
Surly I should do all settings,
Say I have done with all settings, also done with setting some thing like sendmail_from = info@programmingfacts.com and then using some other email id as ‘from’ in php mail function what issues do u think could be raised.
Also person receiving email thru this will always be able to see sendmail_from = info@programmingfacts.com from email details
about 1 year ago
@ avinash – Nop. Whatever email address you will write in mail function for From field in headers, that only shows as from email address. sendmail_from will be using for verification of your email address with smtp settings. This has no connection with your from email address in php mail function. If due to any problems, email will be failed to deliver to recipient than failed message will be sent to sendmail_from.
about 1 year ago
@ avinash – Nop. Whatever email address you will write in mail function for From field in headers, that only shows as from email address. sendmail_from will be using for verification of your email address with smtp settings. This has no connection with your from email address in php mail function. If due to any problems, email will be failed to deliver to recipient than failed message will be sent to sendmail_from.
about 1 year ago
@ Haezal – I have already said i am using MYSQL for my CakePHP application. If you want to look at CakePHP demo application than Google provides so many example modules. I can’t give you the example module as i am developing CakePHP application for my client. Its not a personal. Sorry dude.
about 1 year ago
@ Haezal – I have already said i am using MYSQL for my CakePHP application. If you want to look at CakePHP demo application than Google provides so many example modules. I can’t give you the example module as i am developing CakePHP application for my client. Its not a personal. Sorry dude.
about 1 year ago
Thanks Rakshit for info,
but cant I configure SMTP on localhost itself say if I am using wamp? coz i have seen one configured on linux m/c locally, just i m not aware how was it configured.
about 1 year ago
Thanks Rakshit for info,
but cant I configure SMTP on localhost itself say if I am using wamp? coz i have seen one configured on linux m/c locally, just i m not aware how was it configured.
about 1 year ago
@Avinash, You must have smtp server details.
about 1 year ago
@Avinash, You must have smtp server details.
about 1 year ago
Hi,
can i use smtp.gmail.com and my gmail account instead of my ISP smtp server name to send emails from localhost???
Thanks in advance.
CAM
about 1 year ago
Hi,
can i use smtp.gmail.com and my gmail account instead of my ISP smtp server name to send emails from localhost???
Thanks in advance.
CAM
about 1 year ago
Hey thanks Rakshit.. and helped me a lot… With clear steps….
about 1 year ago
hai i need to create a label like gmail label in my project how can i do this
about 8 months ago
useful information thanx
)
about 8 months ago
Thanks man! This works!!!
about 7 months ago
Hi,
How can I set my SMTP? I use subdomain provided by http://www.azok.org
Pls help me and say about smtp.
about 5 months ago
I do as you say but still getting
Message failed! Check your settings and check with your hosting provider
Could not instantiate mail function.
can you please help
about 4 months ago
i want to mail via my localhost(xampp). i m using bsnl as my isp and use yahoo to send mails. setup made in php.ini -> smtp=smtp.bsnl.co.in and others as u detailed in your articles. but “SMTP server response:550 5.7.1 relaying denied” error comes. please guide me..
about 3 months ago
I did exactly as you said. While compiling, its showing “Email Sent”, but did not reach to my Inbox or Spam folder.
Any Idea..?
about 2 months ago
Thanx a ton for this one, I really needed to get my mail up and running locally!