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% [?]

Enter your email address and get recent tutorials, tips, tricks and scripts of PHP, Ajax, JavaScript and CSS directly delivered to you email inbox:

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”

  1. Siyab on December 27th, 2007 6:24 am

    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)! ]

  2. Anthony on January 6th, 2008 5:27 pm

    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.

  3. Sending email through your local host through WAMP or XAMPP on January 14th, 2008 3:51 pm

    [...] Sourced from: Roshan’s Blog [...]

  4. sriram on January 23rd, 2008 2:46 am

    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

  5. Roshan on January 23rd, 2008 6:42 am

    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.

  6. jishi on January 30th, 2008 4:36 am

    how to send email automatically by setting a particular time in windows by using php

  7. Roshan on January 30th, 2008 6:05 am

    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.

  8. Sending email through your localhost using WAMP or XAMPP. | Menekali on February 23rd, 2008 12:40 am

    [...] Roshans Blog. addthis_url = [...]

  9. agentcris on April 6th, 2008 4:06 pm

    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

  10. Roshan on April 6th, 2008 4:47 pm

    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…

  11. Ali on May 5th, 2008 11:39 am

    I have a problem that my php file does work on xampp but not in wamp……why ?

  12. Roshan on May 5th, 2008 4:44 pm

    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?

  13. Sam on May 10th, 2008 6:34 pm

    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.

  14. Roshan on May 11th, 2008 5:22 am

    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

  15. Sam on May 11th, 2008 1:55 pm

    I am a little confused, where do you specify the user id and password for the smtp server.

  16. Roshan on May 11th, 2008 6:01 pm

    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

  17. D. Baishya on May 15th, 2008 1:14 pm

    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.

  18. Roshan on May 15th, 2008 6:12 pm

    thanks for a such a lovely comment D.Baishya…you’ll be the first one to donate for this blog if you do so…

  19. Yoosha on May 25th, 2008 3:04 pm

    Thats not work!
    Error on host & port(Local)!

  20. Roshan on May 25th, 2008 3:11 pm

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

  21. Shah Khan on May 26th, 2008 6:08 pm

    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

    ????

  22. Roshan on May 27th, 2008 5:06 am

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

  23. Vladimir on June 1st, 2008 4:41 pm

    Use Denwer. It use local folder to save sended mail. I remove my xampp and now I user Denwer!

  24. Roshan on June 2nd, 2008 4:31 am

    oh…..I didn’t know about devwer..have to check that out…

  25. Darren Azzopardi on June 17th, 2008 3:25 pm

    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! :)

  26. Roshan on June 17th, 2008 4:08 pm

    Hey Darren…Thanks a lot for motivation…which surely boost up to write more and more tutorial in this blog…

  27. Bob Prouty on June 25th, 2008 12:21 am

    My ISP requires a username and password. How can I set this?

  28. Shyam Timalsina on June 29th, 2008 3:11 am

    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!

  29. Praveen Gupta on July 11th, 2008 12:28 pm

    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

  30. erwin on July 19th, 2008 2:20 am

    do i still have to set up my microsoft outlook express? because it always pop when i click send.

  31. Roshan on July 19th, 2008 4:49 am

    @erwin - no you don’t havwe to set up any thing in microsoft outlook express, it fairly simple technique from PHP

  32. erwin on July 19th, 2008 5:18 am

    thanks for the reply…but how come outlook express always pop up when i click send…by the way im using WAMPserver…

  33. ratna on August 15th, 2008 7:02 am

    rat32chat.freehostia.com is completely php coded
    to check message of friends we need to refresh
    how to make it automatic
    mail me

  34. Roshan on August 15th, 2008 3:21 pm

    @ratna - I don’t think freehostia.com provide smtp facility for free web hosting account..

Leave a Reply