Sending e-mail from localhost in PHP in Windows Environment
Posted on December 26, 2007
Filed Under how-to, php, tips and technique
Have you ever been frustrating, why e-mail is not going from the localhost while using XAMPP or WAMP or any other PHP servers in windows environment? well in that situation i think i can help you.In this article i am going to tell you how to send e-mail from localhost in PHP.
1) Open the “php.ini“. You should know where it is located because it depends upon the particular server you’re running.
2) Search for the attribute called “SMTP” in the php.ini file.Generally you can find the line “SMTP=localhost“. change the localhost to the smtp server name of your ISP. And, there is another attribute called “smtp_port” which should be set to 25.I’ve set the following values in my php.ini file.
SMTP = smtp.wlink.com.np
smtp_port = 25
3) Restart the apache server so that PHP modules and attributes will be reloaded.
4) Now try to send the mail using the mail() function ,
mail(”you@yourdomain.com”,”test subject”,”test body”);
you might get the warning like this,
Warning: mail() [function.mail]: “sendmail_from” not set in php.ini or custom “From:” header missing in C:\Program Files\xampp\htdocs\testmail.php on line 1
5) Now specify the following headers and try to send the mail again,
$headers = ‘MIME-Version: 1.0′ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;
$headers .= ‘From: sender@sender.com’ . “\r\n”;
mail(”you@yourdomain.com”,”test subject”,”test body”,$headers);
Well that’s all, the mail is sent to “you@yourdomain.com” from the localhost.
Note : Some smtp server verifies the email address of the sender so the email address which is in the place of “sender@sender.com” should be a valid and existing email address otherwise mail might not be sent to the “you@yourdomain.com”.
If you have any question or feedback then write at bhattarairoshan at yahoo dot com.
The wireless internet service providers provide all kinds of the facilities to enjoy the high quality of high speed internet. There is a need of developing the most exclusive website design templates for building more wonderful websites. There is need of getting some skills for installing the wireless routers in the professional manner. The cingular wireless networks are very important in providing the most exclusive services of internet. There are several reliable companies which are main source of wireless internet coverage in all over the world. The networks of voip company is designed to facilitate the customers with internet phone services in the cheap rates.Popularity: 34% [?]
Follow me on twitter at http://twitter.com/roshanbh.
Related Posts
» Some Magical and weired bug in Microsoft Windows
» Few Programming Jokes
» How to run a php file(script) automatically in a certain interval - Using Cron job
» Win a template worth $29.9 from buytemplates.net at free of cost
Comments
34 Responses to “Sending e-mail from localhost in PHP in Windows Environment”
Leave a Reply






thanks for this post, budddy! I was long freaked out how to send email through my localhost server… now my prob’s solved. Thanks again!
[ btw, thanks for commenting on my blog(www.puttingblogsfirst.com)! ]
Very interesting and worked for me with XAMPP
In my version of XAMPP I had the error in step 4/ then noticed this below the SMTP setting:
; For Win32 only.
;sendmail_from = me@example.com
I uncommented it and it worked without the error although doing step 5/ has the same effect.
[...] Sourced from: Roshan’s Blog [...]
thanks for ur help. but, should i need to install a separate SMTP server in my machine. First of all, i want to test the mail() function. Can i do this without internet i.e in the LAN? pls reply
you don’t need to install a separate SMTP server just call your ISP(internet service provider) and ask for the smtp host name and you can not do it without internet connection.
how to send email automatically by setting a particular time in windows by using php
In Linux you can use the cron-tab to execute a file in a particular time you can look at this post
http://roshanbh.com.np/2008/01/how-to-run-a-php-file-automatically-in-a-certain-interval-using-cron-job.html
But in the windows you need to take help from the scheduled task to do it but I’m not pretty sure that it is going to work in windows.
[...] Roshans Blog. addthis_url = [...]
Roshan,
How do i know the SMTP server name of my ISP. Yeah i know this is an absolutely dumb question. But please help me out.. Is it something related to the domain that i should purchase or the provider of my internet? Please help
Oh if you’re purchasing the domain and web space then smtp server comes with the hosting space and if you’re using localhost then contact your ISP, they will give you the name of the smtp server of your ISP..
hope this helps…
I have a problem that my php file does work on xampp but not in wamp……why ?
Are you using the same smtp server’s name in both wamp and xampp ? and are you sure that smtp is set to proper value in php.ini of wamp?
Can I use the gmail gateway smtp.gmail.com at port 25. But where do i specify the user id and password. Something similar to what Windows Mail uses.
I don’t think you can use the smtp.gmail.com using this tips…better ask with your ISP provider what is their smtp server name to send email
I am a little confused, where do you specify the user id and password for the smtp server.
In this step SMTP-AUTH(http://en.wikipedia.org/wiki/SMTP-AUTH)
is not required…if you ask the unauthenticated SMTP server name with your ISP provider they will just provide the name and you don’t need any smtp authentication for this…hope this helps
Sweet Tutorial. This time I really wanted to DIGG/Reddit/Y!Buzz this article(tutorial) and I see nothing click. I think I will be returning again and if it continues to help me expect more than $2 of donation.
thanks for a such a lovely comment D.Baishya…you’ll be the first one to donate for this blog if you do so…
Thats not work!
Error on host & port(Local)!
Did you follow the all the instruction properly ? Did you set the proper smtp server’s name?
In some cases, it takes a bit longer time to send email set the max_execution_time in php.ini to a bit higher..
Please help i got this error:
Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in E:\xampp\htdocs\pages\contact_us.php on line 8
????
hi khan…..it your ISP which can help you as they are not allowing to send the mail from your localhost, ask them to allow send email from localhost..
Use Denwer. It use local folder to save sended mail. I remove my xampp and now I user Denwer!
oh…..I didn’t know about devwer..have to check that out…
Hi Roshan,
Not many developers can write good tutorials but you break the mold. This was really good, short and straight to the point.
WELL DONE!
Hey Darren…Thanks a lot for motivation…which surely boost up to write more and more tutorial in this blog…
My ISP requires a username and password. How can I set this?
Dhanyabad!!!
Thank you. I was trying to send mail from my local computer in php, apache server. I was having problem with the SMTP server. My isp is NTC and I got the idea to change SMTP setting in php.ini to smtp.ntc.net.np
Thanks again!
Hi,
I am getting this error, any help would be appreciated.
Warning: mail() [function.mail]: SMTP server response: 550 must be authenticated
Thanks in advance.
-Praveen Gupta
do i still have to set up my microsoft outlook express? because it always pop when i click send.
@erwin - no you don’t havwe to set up any thing in microsoft outlook express, it fairly simple technique from PHP
thanks for the reply…but how come outlook express always pop up when i click send…by the way im using WAMPserver…
rat32chat.freehostia.com is completely php coded
to check message of friends we need to refresh
how to make it automatic
mail me
@ratna - I don’t think freehostia.com provide smtp facility for free web hosting account..