Please try the previous solution [PHPMailer] first to send email from localhost. It is much more efficient.
The new WAMP Server’s PHP and stand-alone PHP v5.3+, are now NOT available with some of the extensions required to implement the previous solution [PHPMailer] (there is a workaround to install the missing extension(s), described in the linked article). So an alternate and much less efficient (slower, but negligible low-speed for development platform (WAMP/localhost)) solution can be implemented, as below:
This solution requires sendmail.exe (a Command Line Interface (CLI) executable which accepts email from PHP, connects to an SMTP server and sends email). You will not require to use it by command, don’t bother about it ๐ Download the sendmail.zip and follow these steps:
- Create a folder named “sendmail” in “C:\wamp\”.
- Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
- Open the “sendmail.ini” file and configure it as following
- smtp_server=smtp.gmail.com
- smtp_port=465
- smtp_ssl=ssl
- default_domain=localhost
- error_logfile=error.log
- debug_logfile=debug.log
- auth_username=[your_gmail_account_username]@gmail.com
- auth_password=[your_gmail_account_password]
- pop3_server=
- pop3_username=
- pop3_password=
- force_sender=
- force_recipient=
- hostname=localhost
You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. Enable these log file settings if you don’t get able to send email using sendmail.
- Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:
- Enable “php_openssl” and “php_sockets” extensions for PHP compiler:
- Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):
[mail function] ; For Win32 only. ; http://php.net/smtp ;SMTP = ; http://php.net/smtp-port ;smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = you@domain.com ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). ; http://php.net/sendmail-path sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
- Restart WAMP Server.
- Create a PHP file and write the following code in it:
<?php $to = 'recipient@yahoo.com'; $subject = 'Testing sendmail.exe'; $message = 'Hi, you just received an email using sendmail!'; $headers = 'From: [your_gmail_account_username]@gmail.com' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=utf-8'; if(mail($to, $subject, $message, $headers)) echo "Email sent"; else echo "Email sending failed"; ?>
- Make appropriate changes in $to and $headers variables to set recipient and sender (“From” header) addresses. Save it as “send-mail.php”. (You can save it anywhere or inside any sub-folder in “C:\wamp\www”.)
- Open this file in browser, it MUST work now ๐
sendmail_path = "C:\Progra~1\PHP\sendmail\sendmail.exe -t -i"
). Thanks to Douglas.
Socket Error # 10060
Connection timed out
).Socket Error # 10060<EOL>Connection timed out
. All worked fine after I disconnected Tata Docomo 2G and tried with BSNL Broadband and Idea 3G (on the same dongle). So, I assume Tata Docomo 2G/GPRS, BSNL Dial-up, Airtel GPRS etc. slow connections would not work when using sendmail.exe, may be because of inability of synchronization of communication between sendmail.exe and the mail server on slow internet connection.From Shridharan Perumal:
Few months ago, using your tutorial, I configured mail server in WAMP succesfully. I reinstalled WAMP and tried the same and did as mentioned in the comments area but it didn’t worked (Socket Error # 10060). When Googled, I didn’t got any proper info to solve this. At last, I think I found a reason for this, this is due to Google’s modification. Configuring Stunnel is the solution for this. Here is the post that helped me — http://yogeshchaugule.com/blog/2013/configure-sendmail-wamp.
After a bit of tinkering I finally got it to work. I had to enable less secure apps in my google account settings to get it to work. Just thought I should let you know in case you wanted to add it to your article. This is the link https://www.google.com/settings/security/lesssecureapps.
Thanks. You really helped me out.
this error came what do i do???
error:
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 C:\wamp\www\colleges\mail.php on line 10
You might have forget to COMMENT 2 settings in php.ini file.
Ensure that semicolon is put against “SMTP =” and “smtp_port = 25” lines to make these lines as comment in php.ini file, as below:
[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25
I got the same error which Nivas got. And the solution you gave, i tried that also but it is not working.
To send mail from localhost (WAMP, XAMP, or LAMP) you can use PHPMailer package(Download Link http://code.google.com/a/apache-extras.org/p/phpmailer/ ). After downloading this package ->Extract->Copy the full folder into your project folder->and use the doc folder for help. In example folder there is one file called testmailer.php. Change the parameter as your need.
Examle:
You have to change these parameters to your requirements.
…….code…..
$mail->Username = “abc@gmail.com”; // GMAIL username
$mail->Password = “abcdefgh”;
……..code…..
$mail->AddAddress(“desination@gmail.com”,”Nick name”);
…….code…..
For help you can mail us.. shashidharkulal@gmail.com
You are awesome !!! works perfect for me!! Thanks!! ๐
yipiii….works on me thanks ๐
i got the email in my id but the From address is always the same….is it because of the authusername and authpassword……please help
Yes, this is obvious. By using the method mentioned in this article, you send email from your GMail account and so the From will contain your GMail address.
This article demonstrates “Send email from localhost/WAMP Server…”, you should/can not use this method when putting the code on actual online server. Therefore it is Okay to get your GMail’s email address in From field when used on WAMP Server. On online server you will need to use PHPMailer or PHP’s core mail() function or PEAR’s Mail facility. When you send email from online server, you should be able to use your server’s email server and SMTP or sendmail facility to send email using mail() function or PHPMailer or PEAR 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 C:\wamp\www\project\view-mail.php on line 292 Call Stack #TimeMemoryFunctionLocation 10.0007407584{main}( )..\view-mail.php:0 20.0059437416mail ( )..\view-mail.php:292 Email sending failed” >
i followed all ur steps still getting same error
hey there is no error but i still can’t get the mail
@suchitra, @Nidhi
There must be some problem. Sometimes error will not be displayed but you can check for errors in the error log and debug log files. In the sendmail.ini file, specify files names for the “error_logfile” and “debug_logfile” properties. And after sending a trial email check the error and debug log files. Also, don’t forget to check the spam folder.
it may be due to the proxy setup.
pleas check wether you put ON your proxy or NOT , if it is ON then remove your proxy and create a no proxy connection. ๐ ๐
๐
many problem here like a @suchitra etc…
the problem same is everything is okey no error and succes when send email. BUT when check email not getting email. and teh solution is you must check sendmail_path = “C:\wamp\sendmail\sendmail.exe -t -i”
the extrax file usualy in w:\wamp|bin|sendmail so same your path extrak file sendmile :
sendmail_path = “C:\wamp\bin\sendmail\sendmail.exe -t -i”
thanks a lot
i got msg as email sent but i didn’t receive any mail at all…
i follow all the steps mentioned here..
I see the error log it display as “Module ‘smtp’ already loaded in Unknown on line 0”
and also i save the sendmail folder in bin…
but it doesnt work…
I think there are more than one line with “extension=php_smtp.dll” in php.ini; there must be only 1 line for each extension. So, to solve the error, open php.ini, search for “extension=php_smtp” and if there are two lines with this same then remove any one of the lines.
yes sir i change that but still i got the message as “email sent” but no email in my account both in spam and inbox…
Please read my replies to others’ comments describing such problem and follow and thoroughly check this article for any step(s) missed by you.
there is no error but i m getting sending failed message
I may not be able to help you with only to “Sending failed” message. Now this will require to see your code myself. I will be happy to help you by Teamviewer.
Hi…suchitra
I also got the same error….
Make sure that the “sandmail” folder where the “sendmail.exe” store are in “C:\wamp\bin\”….Otherwise the massage can be failed.
The folder of sendmail can be anywhere on your harddisk. But wherever you put it, just be sure that you have also specified the same correct path for “sendmail_path” option in the php.ini file.
Great job!
After a long time of re-configuring and testing, i finally made it work!
๐ ๐
must say its WOOORKING. ๐
Thank you very much! Perfect!!!!!!
๐
Hi,
I dont get any error and also dont see the message in my inbox or spam. I followed all ur steps.
Where could the error be?
Please read the reply to the comments of “suchitra”.
Also be sure about the port of your SMTP server. Sometimes webmasters changes SMTP port from default 25 to something else. You need to first verify this setting from server’s control panel or server’s customer help center.
the post ws really helpful… thanku ๐ ๐
hi thanks for the helpful post.
I got no error but didnโt get any email too. I tried to access the file error.log and debug.log . Please help. Thanks again for the post
Sorry for this late reply.
Please read the reply to the comments of โtanโ.
Also, if you are sending email from an online server, its must have an email account having the same email address which you are using for sending email from. You should ensure that your server supports SSL.
You may also try changing port of GMail from 465 to 587 and/or removing “ssl” (delete “ssl”, keep blank) from “smtp_ssl” setting in the sendmail.ini file.
thanks alot. worked well. ๐
Hi, Thanks for the post.
Really, it is helpful.
๐
Oh my gosh!,
it’s works!
Wrote from Argentina!,
Best Regards
Juan.
It Works in me but I can’t find the send-mail.php. What should I do?
Please tell me I need this to work
Thanks and God Bless, This post is very helpful ๐ Keep It up!!
cheers
John
Hmmm, now that’s strange! If it is working, then you know that where the send-mail.php is actually. If you have followed the same procedures as mentioned in this article, you are opening the send-mail.php in your browser!
Take a look at the code below this line “Create a PHP file and write the following code in it” in the article. That code is saved in the send-mail.php file.
Hi, thanks for the answer. There’s something bothering in my mind but I dont know how to tell it. I just know how the logic goes.
localhost -> Send Email -> Windows Mail
It possible to do that using localhost? or its just only work when the site is live?
Sorry, I really can’t understand what you want to say by “localhost -> Send Email -> Windows Mail”. Please explain.
I’m sorry for not clearing about my question.
Can I execute send email function from localhost then Im going to receive it on my Windows Mail?
Yes, it should work. Why don’t you just try it buddy. Good luck.
Thanks for the post!
But in my PHP->PHP extensions I have not found php_smtp.
What does it mean?
Best Regards,
Dan
As I have wrote in the 2nd paragraph “The new WAMP Serverโs PHP and stand-alone PHP v5.3+, are now not available with some of the extensions required to implement the previous solution.“, so, that required but missing extension is php_smtp in new WAMP Server versions.
THANK YOU!!! for this simple and elegant solution.
๐
Its a Useful and good Article. ๐ ๐
It work ! , Thanks alot
Best Wishes,
Mahmoud
hi can we send multiple attachment from localhost
can any one share me the code
Thanks in advance
Here is my article to solve your problem.
thanks…
๐ฏ
This Kind Of ERROR occure
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:\wamp\www\Mail\send-mail.php on line 10
Email sending failed
I Follow all the step but somting problem..plz help me
You could have made mistake while configuring php.ini file. Check that all the lines (except first, [main function]), copy-pasted in this article, are commented (have semicolon as first characters in the lines). Most probably you have forgot to comment the line “smtp_port = 25” in php.ini.
Also ensure which php.ini file your server is using, “wamp\bin\apache\apacheX.X.X\bin\php.ini” or “wamp\bin\php\phpX.X.X\php.ini”?
I am getting this error log in debug log.txt file in send mail directory
12/08/10 12:33:57 ** — MESSAGE BEGIN —
12/08/10 12:33:57 ** To: d.sandip59@gmail.com
12/08/10 12:33:57 ** Subject: Testing sendmail.exe
12/08/10 12:33:57 ** X-PHP-Originating-Script: 0:test.php
12/08/10 12:33:57 ** From: admin@gmail.com
12/08/10 12:33:57 ** Reply-To: d.sandip59@gmail.com
12/08/10 12:33:57 ** MIME-Version: 1.0
12/08/10 12:33:57 ** Content-type: text/html; charset=iso-8859-1
12/08/10 12:33:57 ** X-Mailer: PHP/5.3.8
12/08/10 12:33:57 **
12/08/10 12:33:57 ** Hi, you just received an email using sendmail!
12/08/10 12:33:57 ** — MESSAGE END —
12/08/10 12:33:57 ** Connecting to smtp.gmail.com:465
12/08/10 12:33:58 ** Disconnected.
12/08/10 12:33:58 ** Disconnected.
12/08/10 12:33:58 ** Disconnected.
12/08/10 12:33:58 ** Socket Error # 10061Connection refused.
Please suggest me any solution for me. ๐
It seems you haven’t configured your GMail account properly. Please check the first image in this article for GMail account configuration under “Enable IMAP Access in your GMailโs Settings” topic. If it is ok, try the things specified in my this comment to other user.
Hi..
I followed all the steps as you mention…But I can’t send mail. There is no error…But it returns that “Email sending failed” ….What should i do to fix this problem?
Hi…
I just fixed the problem…Right now it work perfectly….The problem was…you mention that “sendmail” folder is in “C:\wamp\” directory…and when i keep that sendmail folder in “C:\wamp\bin\” folder then it run perfectly….any way Thanks a lot…
The folder of sendmail can be anywhere on your harddisk. But wherever you put it, just be sure that you have also specified the same correct path for “sendmail_path” option in the php.ini file.
I know dat…Anyways thanks a lot….
We had the same problem. And it worked by moving it into c:\wamp\bin\sendmail\ Thanks!
finally it worked properly
Hi Nikunj,
I have tried the above steps mentioned by you. But when I am opening the send-mail.php file in the browser the page goes blank. Even I am not getting error log file generated under the send mail directory. I have uncommented both error_logfile & debug_logfile in sendmail.ini but still the log files are not generated. I am using the wamp server version 2.2. Browser is mozilla 13.0.1
Kindly help out and please let me know where I am doing mistake.
Please check my above comment reply to parimal’s comment otherwise I have doubt that I can solve your problem.
Hi Nikunj,
I have studied your above comment for the Parimal. I have done the same configuration as you have mentioned in the article. I have already configured the php.ini file under wamp\bin\apache\apache2.2.22/bin/php.ini .Now I have done the same configuration for the wamp\bin\php\php5.3.13\php.ini also. But still I am not getting any mail and the error.
The problem is that I am not able to get the failure logs so that I can forward it you. As the log files are not generated under the send mail directory.
If there is nothing in the sendmail’s log files or log files even doesn’t exist, it means the sendmail.exe is not executing when mail() function is called. So the reason could be that you could have set incorrect path to sendmail.exe, but as you have said you have confirmed this setting; another problem could be that the sendmail.exe is corrupt because of virus or anything else, try replacing it. If still there is no error in the log files, check for the files’ and its folder’s write permission.
You should also check your spam folder of recipient and also check for filters.
Also note that sending email from Yahoo and Hotmail’s SMTP server would not work, however this doesn’t seems to be a case in your problem. If still you are unable to send email, try older version of WAMP or try XAMPP, it is very much similar to WAMP Server.
these is a very good thing……………i try it and it is a very good thing ๐
๐ Thanx . Very nice code n it works for me
how to find the error log and debug log files pls guys help me
You would find the debug.log and error.log files in the sendmail’s folder if any error is occuring when sending email; check the configuring sendmail.ini file section in this article. If you aren’t receiving sent email and there is an error but the error.log and/or debug.log files are not generated automatically, then there could be a problem about write permission in the sendmail folder. In this case you can manually create blank error.log and debug.log files and give proper write permission to them.
I am getting an error in error log file as under:
Socket Error # 11001 host not found.
What can be the possible reason?
This error is saying that “host not found” which means either you have given incorrect host name for SMTP server OR your mail server is not discoverable using the host name. So, either you need to specify correct host name OR you can try host’s IP address instead of domain name. These are the most probable reasons but there could be other reason(s) for this error.
Please check these pages for more information:
http://kbase.pscs.co.uk/index.php?article=28
http://www.activehelper.com/community-forum/general-discussion/socket-error-11001-host-not-found.html
(The next one is not directly related but you might find some useful info regarding the same issue.)
http://forum.teamspeak.com/showthread.php/14420-Socket-Error-(11001-11004)
Nice article, worked for me ๐
This works perfectly for me, except one tiny thing. I tried changing the info from my Gmail account to my Hotmail account. No matter what though, it still seems to continue sending emails from the Gmail account, even when the info in sendmail.ini is that of my Hotmail account. Any suggestions?
This must not be possible. After changing appropriate info in sendmail.ini save it, close it and reopen it before sending email and ensure that the info you had set is still there.
You should also check your GMail and Hotmail accounts’ settings that they are not configured to send/receive emails from each other by their imports-email-from-another-account features.
Also check that “from” and “reply-to” email addresses are properly set.
Awesome!
I was try from long time…..
Thank you very much…. from the bottom of my heart
Thank you…. it is working
I have got message Email Sent .But cant find mail in gmail.
Please ensure that you have correctly configured the sendmail.ini file and correct path to it is set in the php.ini file.
Also check my replies to other commentators.
Nadeem,
Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.
Thanks in advance for you reply…
I have tried it .It sent the message that email is sent but i did not find the mail in the reciever’s inbox
Check the above reply to Nadeem’s comment.
The browser displays a message “Email not Sent” and the error.log file updates with a new mwssage 12/09/29 21:38:01 : Socket Error # 10060Connection timed out.
The error is occurring, I think, because you are trying to send through an SMTP server other than GMail, and that server is not responding on the port specified by you in the sendmail.ini file. Please check your server’s configuration for correct open port of its SMTP server. Another possibility could be that the server is configured to deny connection from outside of the server.
Gyana iam also getting this error in error.log, but getting email sent in browser… Can you please guide me how you fixed that issue
Thanks
Everything works fine on Windows 7. Just tried installing on Windows 8 WAMP and getting Socket Error # 10060Connection timed out
I’ve changed sendmail.ini from
smtp_ssl=ssl
to
smtp_ssl=none
and it’s all working on Win 8 too!
hey i have done everything correctly but it is now show that Email Sending fail..
what shud i do..
Please check my replies to the comments of Suchitra and Onjon‘s comments and all other replies/comments. Also don’t forget to read the italicized content at the top of this article.
how to fix this problem…??? the error meassage: 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 C:\wamp\www\shopping\send-mail.php on line 18
i already follow all the step provide..how to fix these error..?please help… ๐
Please check NIVAS‘s comment and my reply to him. Please also read all other replies/comments.
YOUR THE BOSSSSSSS…you save my life..!! thank you so much!!
Thanx a milion time ๐ omg I have read at least 20 blogs and tutorials about this. I have downloaded few aplplications and so on a you explain sending email from localhost so clearly and easily you have to get a Nobel Price at least from me ๐ I am so happy you won’t believe ๐ ๐ :D. I never leave a reply if I am looking for some problem but you make my day with this article so I have to leave a comment ๐ and sorry if it’s too long but I am really happy
Big thank you !
Hey thanks for this gr8 tut ๐
I’m getting the following error
http://prntscr.com/i68mw
i don’t have any idea how to solve this.. ๐ก
It seems you don’t sufficient rights to run/execute the sendmail.exe. Please check sendmail.exe’s properties and give sufficient rights to your user account.
i have completed all process. but when i sent a message . i got successfully.
but it did not reached there
Please check my replies to others’ comments.
i got apache_error is
[Sun Oct 28 15:28:17 2012] [notice] Child 920: Starting thread to listen on port 80.
The system cannot find the path specified.
Hmmm, that’s something new after many days on this article!
Well, it seems a file is not available at a specified path and most probably, as Apache also logs some PHP errors, this error seems pointing towards sendmail.exe file. So, please check the php.ini file for correctness of the sendmail.exe’s path. (Remember there are 2 php.ini files, one for apache and another for php; please check above somewhere in comments for the actual paths to them and which you should edit.) And also check that you have sufficient rights to view/access/run/execute the sendmail.exe.
Oh but if these are the problems, I should say, there is nothing new ๐
i is too good, as i think.
Email sending failed ๐ฅ
Provide more info or please check my replies to others’ comments.
i tried this selution but don’t work
and “Email sending failed” showing in page
Provide more info and/or please check my replies to othersโ comments.
thanks a tonnes yaa ๐ ๐ ๐ r……… godd i searched so many articles… god bless you…. thanks and lots of thanks… ๐ ๐ ๐ ๐
thanks it works!
๐
Hi Nikunj,
Thank You very much, your code made our work sucessfull !!!!!!
12/11/18 16:07:58 : Socket Error # 11001Host not found.
ERROR
Please check my reply to Yasir’s comment.
It works great. Thank you โ โ
๐ Working fine for me..!!
Great work ! work perfectly !
in my php extensions there is np php_smtp,
but still work perfectly.
Thanks
I’m keep getting following error
12/11/22 18:46:58 ** — MESSAGE BEGIN —
12/11/22 18:46:58 ** To: ranuradis@gmail.com
12/11/22 18:46:58 ** Subject: Testing sendmail
12/11/22 18:46:58 ** X-PHP-Originating-Script: 0:send-mail.php
12/11/22 18:46:58 ** From: sender@gmail.com
12/11/22 18:46:58 ** Reply-To: sender@gmail.com
12/11/22 18:46:58 ** MIME-Version: 1.0
12/11/22 18:46:58 ** Content-type: text/html; charset=iso-8859-1
12/11/22 18:46:58 ** X-Mailer: PHP/5.3.13
12/11/22 18:46:58 **
12/11/22 18:46:58 ** Hi, you just received an email using sendmail!
12/11/22 18:46:58 ** — MESSAGE END —
12/11/22 18:46:58 ** Connecting to smtp.gmail.com:465
12/11/22 18:46:59 ** Connected.
12/11/22 18:56:58 ** Disconnected.
12/11/22 18:56:58 ** Disconnected.
12/11/22 18:56:58 ** Disconnected.
12/11/22 18:56:58 ** Connection Closed Gracefully.
Please ensure that Enable IMAP Access in your GMail’s Settings is enabled:
Gmail Settings -> Forwarding and POP/IMAP -> IMAP Access
Also, in the log you have pasted here, “sender@gmail.com” is set as From header’s value, is it your real email address or you have just changed it to hide identity here? “From” header must be same as your Gmail address.
I am correctly configured IMAP (as your screenshot). I did not hide my identity and From is set to “sender@gmail.com”. But after I set it to my email address, mail sending was failed. “else” part occurred of your code (Email sending failed)
Please read my reply to Prankur’s comment.
Its working fine now. Excellent job and thanks a lot for correcting me on my errors. Thank again!!!
when i run the file in browser i got the msg Email sent but i didn’t get the mail.
Please read my replies to others’ comments of such problem.
Please help me i didn’t get any idea from any of your comment….
Brother, I am sorry, these all is written in simple English. However, you can ask me if you can’t understand “(a) specific” reply/comment.
Hi Nikunj,
Thanks for ur help my code was not running bcoz i activated 2 step verification in my gmail account now i deactivate my 2 step verification from my gmail account and my code is now working properly once again thanks alot….
Great!!! thanks!!!!
Hey there is an error…..
“Email sending failed”
Please help !
Please check others’ comments and my replies to them. If still you couldn’t solve it then I can’t help with only your provided information, please provide more information.
Thanks its really working….. ๐ ๐
Hey,
I did read your comments. Now the page is saying EMAIL SENT but I can’t find any mail though in my inbox. I rechecked my senmail.ini file but cant figure out what exactly is wrong. Would appreciate your help. Thanks.
Please ensure that 2-steps-verification is disabled in GMail. (If you don’t know about 2-steps-verification, you don’t need to worry about it, it is disabled by default.)
Sakshi,
Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.
Thanks in advance for you reply…
yes it is disabled.
Hi Nikunj I followed all the steps u provided below still i getting {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 C:\wamp\www\TASKS\Email\mail.php on line 10} error..
Please help me..
Found the solution.. Restart the server. Thanx a lot. ๐
hi ,
somebody help me.. i think i already do the rigth thing but still i get sending email failed..
appreciate for any help
tnx,
jr
Hi ,
Everything went fine but haven’t received any email in my inbox.
Please help.
Thanks
Ani
hi Nikunj! This is a really helpful post! Thank u so much for it! I followed everything according to how you explained! I am getting the ’email sent’ message but not the email on my Id! Read your replies to everybody else as well but not able to figure out what to do! Can u please suggest something that how it be detected where things might be going wrong?
MS,
Could you share how you resolved your problem. I am getting the “email sent” message but nothing in my “In-Box”. No errors on error-logs or debug-log either.
Thanks in advance for you reply…
Hi
Great tut…the best ๐
How can I get this to function with a localhost wordpress please..any idea?
thx
DJ
Thanks.
Good question about integrating WordPress on localhost with this facility. I had thought about it too; but presently I don’t have much time to research on it. So please either try yourself or wait until I get time to do this. However, I think this must not be difficult. I don’t remember but I think there is some option to configure email related info when installing WordPress, please check it. I tried a little bit to find config related to emailing in WordPress files but found nothing yet. Good luck.
Nikunj,
There are plenty of WordPress plugins capable of using smtp/ssl. I host my own WordPress server with all the apps (Apache2.2.19, PHP5.3.6, mySQL5.x.x). Therefore, I use 3rd party mail servers (gmail) to send outgoing mail via my WordPress website applications. Therefore, no need to use “sendmail” to obtain 3rd party mail server. WordPress use PHPMailer…
I didn’t get your point by ” I host my own WordPress server with all the apps…”. Have you installed WordPress on your own computer (WAMP or XAMPP (localhost))?
Sure, WordPress is using PHPMailer, and PHPMailer is the best method for sending email, but it can’t be used if php_smtp extension is not available for PHP compiler. Therefore I have described an alternate method in this article which uses sendmail.exe for sending email from localhost. I think you haven’t read the first two paragraphs of this article.
Aloha Nikunj,
I did read your “wonderful” article and the first two paragraphs. My hosting (localhost) environment is not a WAMP or XAMPP. Nevertheless, I am using a PHP application that’s outside the WordPress environment application. Therefore, the PHP application does not use the WordPress wp-mail function. Therefore I am interested in implementing “sendmail”. I have installed “sendmail”. I have tested sendmail using Glob’s batch example (cmd). The batch works great! However, testing with your above scripts, I get the “Email sent” message. Nevertheless, no gmail in my inbox. Yes, I will re-read your comments from above comments for “not receiving mail in their inbox”. Unfortunately, your commentor’s do not indicate what they did to fix the problem of “Email sent” but no mail in their “in-box”. Sorry for the Blah… Blah…
I personally want to thank you for wonderful article. I investigated (search) many articles on “sendmail” and none could articulate the procedure for installing “sendmail”.
Kind Regards,
from Hawaii Island
Thank you Douglas. I post here only those content which I haven’t found elsewhere, no copy-paste. I think “About this Blog” page would interest you.
Yes, it’s unfortunate that some commentators haven’t commented how they solved their problem of “Email sent” message but “not receiving email in their inbox”. What I believe is, most of them could have just forgot to configure one or two required things to implement this solution. And after knowing about it and solving the problem, they just don’t care about their comment; they might be feeling embarrassed about a silly mistake.
Email sending failed
may i know i get this error???
please…urgent…
You are cool man.This worked for me superb.
For along time I was looking for this on various websites.You explanation is superb.
Thanks.
tnq..buddy… ๐
Thanks for the useful post
Iam using my gmail to send email.
I have followed each step and read all comments/replies & getting message Email Sent in browser, but cant get email neither in yahoo inbox(recipient’s) nor in spam.
Only got this line in error.log file Socket Error 10060 Connection Timed Out
Thanks
At last, a solution that works! THANK YOU ๐
Took a while to realise that my email with Google isn’t @gmail but @mydomain so once I’d set auth_username= to that all works.
No more uploading php files to a test rig on my remote server.
worked right the first time. Super job!
Followed the instructions and it worked perfectly. Thank you very much!
Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\wamp\www\PHPMailer_5.2.2\class.phpmailer.php on line 2378
Can you plz help out : how to solve this errors thanks
Warning: date(): It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\wamp\www\PHPMailer_5.2.2\class.phpmailer.php on line 2382
Could not execute: /usr/sbin/sendmail
This is just a “Warning” which means it is not an “Error” and you can continue without worrying. Warnings mostly appears only on localhost and not on actual server, so you don’t need to worry about.
I can provide 3 ways to hide this warning.
date.timezone = UTC
date_default_timezone_set()
” function to set proper timezone at top in your email sending file. For how to set timezone using “date_default_timezone_set()
” function, check this page: http://in1.php.net/manual/en/function.date-default-timezone-get.phperror_reporting
” to “E_ALL & ~E_NOTICE & ~E_DEPRECATED
” or “E_ALL & ~E_DEPRECATED
“.To see the timezone for your region, check this page: http://in1.php.net/manual/en/timezones.php.
๐ ๐ ๐ ๐ Thanks
hi i am developing a website and i need to send a mail in my website but i cant send a mail.
error occur:SMTP ERROR:Could not connect to smtp host
and im using wamp server there i cant find smtp module what can i do
pls help me
The SMTP ERROR mentioned by you could occur if SMTP server’s address or username or password or port is incorrect. It could also occur if server doesn’t accept connection from outside of its own server space. Please enable logging in sendmail.ini file and check the logs for more info about the error.
The solution provided in this article doesn’t require php_smtp extension.
thanks for ur reply
what we have to specify in default domain of the sendmail.ini file
can you explain me clearly about the configuration and provide me a code for sending mail using wamp server….
but in wamp server i wont have php_smtp in php extension
Everything you need to know is written clearly and in easy grammar in this article and in my reply-comment. If you can’t understand something, please ask to someone whoever is nearby you.
thanks !!! ๐
how do we do that for lamp server ?
I haven’t used LAMP Server and I don’t know how to use sendmail on Linux. But I guess, sendmail is a Linux command and therefore you would just need to set sendmail’s path in php.ini as following:
sendmail_path = "/usr/sbin/sendmail -t -i"
.There should not be any need to download anything for sendmail. But it is possible that you might have had NOT selected to install sendmail when installing Linux; so if you can not find the sendmail on your system, you should be able to install it from Linux installation disk. All other configurations described in this article should work without any change.
You can find more info on Linux’s sendmail at http://linux.about.com/od/commands/l/blcmdl8_sendmai.htm and at http://www.redhat.com/support/resources/howto/RH-sendmail-HOWTO/book1.html.
I Have apache 2.2 server installed . i am trying to send feedback to the gmail email id from php script. when submitted i am 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 D:\wamp\www\kvksite\feedback_form.php on line 14
I have not done any changes in php.ini. lphp.ini the server uses is in wamp/bin/apche2.2/bin directory.
Kindly suggest me step by step how to solve this problem.
You said “I have not done any changes in php.ini.” actually you need to make changes in php.ini. Please read this article carefully and specially about changing the php.ini file.
Thanks Nikunj, its working. ๐
Now I could send the text in the text area to my email id from the feedback form. Please guide me how to get the jpg attached in the feedback form to my email-id. Now I am saving the jpg to a folder on my local system and path in the db. Along with the feedback text i want the jpg also to be attached to my email.
Please read this article and comments below it for attaching file with email: Sending email with attachment from localhost/WAMP Server using sendmail.
I am trying with the code you have given in the article, but i am getting mail sending failed error. and in the error log I am getting 13/02/01 17:00:22 : Socket Error # 10060Connection timed out.
What is the problem.
Please ensure that you have specified correct port and your GMail account setting is configured correctly. If you are using other SMTP server then be sure that it accepts connections from other hosts, not just only its own host.
I’m having trouble… all things is setup and working but the message body turns to a .txt file and downloadable… it is not the usual message bod when it sends.
This shouldn’t happen with the PHP code supplied in this article. You could have merged other code with the code in this article. Please ensure that you have NOT this line in
$headers
:Content-Disposition: attachment
If you have this code than remove it.
I don’t have that line of code. but this is i have now.
$to = $uemail;
$subject = “ScribeNet Email Confirmation”;
$message = “HI! Ciao!”;
$headers = “From: gee@yahoo.com” . “\r\n” .
“Reply-to: geet@yahoo.com” . “\r\n” .
“MIME-Version: 1.0 \r\n” .
“Content-type: text/hmtl; charset=iso-8859-1\r\n”;
if(mail($to, $subject, $message, $headers))
{
echo “Email Sent!”;
}
else
{
echo “Email Sending Failed”;
}
Correct the lines as following:
"Reply-To: sender@gmail.com" . "\r\n" .
"MIME-Version: 1.0" . "\r\n" .
"Content-type: text/html; charset=iso-8859-1" . "\r\n";
The
"\r\n"
does matter to write it outside other header contents.Also, you have misspelled
text/html
, you have writtentext/hmtl
. This is the reason why your email body text is shown as attachment instead of normal HTML body text.Also capitalize “To” in “Reply-To”, it is correct format.
hey thank you so much dude!!!!! your great! I really missed that html thing……
ok no errors now
just sending message failed
Please enable logging of error in sendmail.ini and check for errors in the error log file.
i follow all the process from ur site but im still not getting email in my gmail.
Please read this article carefully, it worked for many, you could have missed something. Read my replies/comments to others’ comments.
I got this error in debug.log file
— MESSAGE BEGIN —
13-01-30 17:14:50 ** To: rajesh07590@gmail.com
13-01-30 17:14:50 ** Subject: Testing sendmail.exe
13-01-30 17:14:50 ** X-PHP-Originating-Script: 0:send-mail.php
13-01-30 17:14:50 ** From: rajesh07590@gmail.com
13-01-30 17:14:50 ** Reply-To: rajesh07590@gmail.com
13-01-30 17:14:50 ** MIME-Version: 1.0
13-01-30 17:14:50 ** Content-type: text/html; charset=iso-8859-1
13-01-30 17:14:50 ** X-Mailer: PHP/5.4.3
13-01-30 17:14:50 **
13-01-30 17:14:50 ** Hi, you just received an email using sendmail!
13-01-30 17:14:50 ** — MESSAGE END —
13-01-30 17:14:50 ** Connecting to smtp.gmail.com:465
13-01-30 17:14:51 ** Connected.
13-01-30 17:14:51 << 220 mx.google.com ESMTP ai8sm1395405pbd.14 – gsmtp
13-01-30 17:14:51 >> EHLO localhost
13-01-30 17:14:51 << 250-mx.google.com at your service, [1.22.205.225]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH XOAUTH2250 ENHANCEDSTATUSCODES
13-01-30 17:14:51 ** Authenticating as rajesh07590@gmial.com
13-01-30 17:14:51 >> AUTH LOGIN
13-01-30 17:14:51 << 334 VXNlcm5hbWU6
13-01-30 17:14:51 >> cmFqZXNoMDc1OTBAZ21pYWwuY29t
13-01-30 17:14:52 << 334 UGFzc3dvcmQ6
13-01-30 17:14:52 >> MDc4NTFhMDU5MA==
13-01-30 17:14:52 << 535-5.7.1 Username and Password not accepted. Learn more at535 5.7.1 http://support.google.com/mail/bin/answer.py?answer=14257 ai8sm1395405pbd.14 – gsmtp
13-01-30 17:14:52 ** Disconnecting from smtp.gmail.com:465
13-01-30 17:14:52 ** Disconnected.
13-01-30 17:14:52 ** Disconnected.
13-01-30 17:14:52 ** Username and Password not accepted. Learn more athttp://support.google.com/mail/bin/answer.py?answer=14257 ai8sm1395405pbd.14 – gsmtp
Please check correctness of your password in sendmail.ini. Also ensure that 2-steps-verification is disabled in GMail.
You may also try changing port of GMail from 465 to 587 and/or removing “ssl” (delete “ssl”, keep blank) for “smtp_ssl” setting in the sendmail.ini file.
Thank you very much it is working fine
I LOVE YOU!
Thank you Mr nikunj , it worked for me …….. ๐
itz showing an error …plz help me…SMTP server response: 550 Invalid recipient: abc@yahoo.in
Please try specifying an existing address. It is possible that the sendmail.exe would check for the existence of recipients’ email account(s) before sending the email.
I had sent an email to notify you about my reply to your comment but the email address (seeliyakvarghese AT gmail DOT com) provided by you is incorrect and therefore the email delivery failed; please provide your correct email address.
hay i got it
n thanks
m try to solve my problem n i succeed and its now work ๐
yuppieee
once again thanks
Just perfect.
I have follow all step by step and it’s working at the first try.
Five minutes to implement it.
Next step how to attach a document….
Thanks to share your knowledge.
mail() [function.mail]: Failed to connect to mailserver at “” port 465, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in C:\wamp\www\sitemap\sendmail.php on line 10
Email sending failed
please help me solve my problem .i read alll comments but still i have this error
Please ensure that you have provided SMTP server address for
smtp_server
setting in sendmail.ini; and semicolon is prefixed against all lines except the last one in the[mail function]
part in the php.ini file.hey…my email is send thanx a lot …this is such a nice article
i only just remove square bracket from sendmail.ini in username and password and i got success my mail send to user
now , my question is can diffrent user or multi ple user send mail using this sendmail or through localhost????
Yes, it is possible to use the same PHP script for sending email on behalf of multiple users. To achieve this, you need one common account of GMail. Write its email address and password in the sendmail.ini file. Then, in the send-mail.php file, substitute the
From
andReply-To
headers (sender@gmail.com) in$headers
variable, to the appropriate users’ email address as following:$sender = $_POST['txtSender']; // get user's email address in form
$headers = 'From: $sender' . "\r\n" .
'Reply-To: $sender' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
thanx for rply
i try it but error is undefine $sender and email sending failed
Have you stored sender’s email address in $sender variable as following? :
$sender = $_POST['txtSender'];
Here,
txtSender
is the name of an HTML Input element in which you should accept the sender’s email address before submitting the form.I can provide you more code but I think you should also use common sense to better understand this thing; it is good for you. It is like, I have provided an algorithm and you need to create a programming script from it. Good Luck. ๐
yeah…k sure…thank you…
now it comes email sending failed ๐
Please read my replies to others’ comments for similar issue.
Nikunj,
Very Well Done!!!!
Thank You!!!
I dont find php_smtp in php extensions. Also, when i check error.log, I get the following error
13/03/11 14:24:25 : Socket Error # 10060Connection timed out.
I even moved the sendmail folder to C:\wamp\bin directory and changed sendmail_path accordingly but still got the same message. I once tried your solution and it worked perfectly fine but after some time i deleted it and now doing it again but I dont know why sending fail is coming .
This article describes sending email using sendmail.exe and it doesn’t require php_smtp PHP extension, otherwise (if php_smtp extension is available) PHPMailer is the best method for sending email.
For the connection timed out error, check that sendmail.exe is not blocked by antivirus or firewall or by any other software. You should be able to manually add it to the allowed list of programs in your firewall application. Also try using 587 port of GMail and ensure that 2-step-verification is disabled in GMail and “smtp_ssl” is specified correctly in sendmail.ini and if you have proxy then check its configuration too.
thank u guys ….. its really working ๐ ๐ ๐
Nice. Its working…
why don’t you post my comment ? i have asked so many times and you post only those comments that appreciates you which is unfair . if a person is asking you for help you should respond as soon as possible . i hope you reply and help me fix the bug .
thanks
I have received and read total 3 comments from you, and posted 2 of them (including this). I haven’t posted your previous comment because there was nothing new in it. And I had personally sent an email to you to help you more, and asked you to send your send-mail.php, php.ini and sendmail.ini files to my email address so that I can view them for any problem in them; but I haven’t got reply from you, please check your inbox/spam folder. I have also sent a GMail chat invitation to help you personally, please sign into chat and check the invitation.
I am not doing any unfair, I am not only posting comments of appreciation, instead I have told over the comment box to not to post comments to say just “Thank you” and told to give rating for this article instead. I am always ready to help everybody regarding the solutions posted on this blog. Still, I am sorry for any misunderstanding.
very useful tutorial..man do have like this tutorial showing how to enable https using wamp?
so glad, thanks
I also want to test https on localhost but I think it would not be possible because https requires SSL certificate for secure encrypted connection between client and server. SSL certi costs hundreds/thousands of dollars. Also, it may not be available for individual, may only be available for registered organizations; and may also need a dedicated/leased line internet connection with static IP address. Still, I hope to research more on it later sometime, can’t say when.
one of my friend has done it b4..its easy to create certi from ur cmd..unfortunately my friend traveled but he left a pdf tutorial for me.. but the thing is that i couldn’t enable ssl..i configured something wrongly i guess..perhaps if u send my ur email i can send the tutorial to u for sharing knowledge.
Oh that’s good. You can send it to : nikunjbhatt84@gmail.com
sent bro.
I got it.
Thanks for the tutorial.
I will try it and inform you whatever the result be.
When I keep the FORCE SENDER=
and FORCE recipient=
as it is …i.e if nothing is provided against the =
The error log shows “sender’s address missing/recipient’s address missing”
why?
And irrespective of the “to” and “from” address in the actual code,the mail is forwarded and received in the forced sender/recipient’s address(if provided)…..
Please help..
As I have said, force_sender and force_recipient settings in sendmail.ini aren’t mandatory. Be sure that you have correctly provided auth_username setting in sendmail.ini file; and sendmail_from setting is commented (has a semicolon at the beginning of this line) in php.ini; and you have correctly provided
$to
in the send-mail.php. The correct syntax for$to
is :$to = "Recipient Name"
. Also don’t provide same email address for sender and recipient.Hello,
Trรจs bien รงa fonctionne ร merveille.
Merci beaucoup !
I am receevg sent message ,but am gettg message in my inbox or spam.I checked out error_logfile,debug_logfile,it is sowing as
error_logfile=error.log,
debug_logfile=debug.log,
I have installed postcast mail server and runned the above code.I also used send mail as u said.I folloed all the steps.My problem is i am able toreceive message in post cast but not gmail or yahho.
I am not able to understand your comment fully. Are you saying that you are getting following data in error_log and debug_log files?:
error_logfile=error.log,
debug_logfile=debug.log.,
It doesn’t seem possible.
And you may be able to receive email in postcast because you are sending through it, so what happens, I think, is you send email through postcast and it just copy it to your inbox because recipient is of user_id@localhost; the email is not going through GMail’s SMTP server.
Thanks for ur reply n Nikunj,
No nikunj i dint find error log file ,debug file inside send mail.I found it inside sendmail.ini it is displaying as
error_logfile=error.log
; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging
;debug_logfile=debug.log
; if your smtp server requires authentication, modify the following two lines
I sent mail from post cast server(by clicking start)i am getting error:Thread 1:Access Denied.
I have doubt is it required to use postcast smtp server?can’t i directly send mail?
I tryed doing this and i got error,if i keep postcast open than it is showing message”Successfully sent”.
If u dont mind can i make a call to u ?
Nijunj
is it required to use post cast server?
I did without post cast and got error( NIVAS) i did what u mentioned in nivas comment but still i am getting same error.
I had tried installing and using many free SMTP servers before 1 year but had no success. I might had missed some configuration, but for a conclusion… I haven’t used SMTP server installed on localhost with WAMP.
If PostCast mail server can work then any other SMTP mail server should work too.
You may call me, you can find my contact number on TechWheels.net’s Contact page.
You have uploaded a fantastic resource.
Thanks it works for very nice articles…
Hey Buddy this one is awesome
Thanks man.
Hi,
I followed all the steps closely but I can email sending failed.
This is my error message.
13/04/01 16:01:31 : Socket Error # 10060Connection timed out.
What should i do?
There are many such comments, please check my replies to those comments.
Hi,
I have checked your replies but to no avail.
But I am unsure on how to check my serverโs configuration for correct open port of its SMTP server. ( I used smtp_port=465 for smtp.gmail.com)
I also allowed access to sendmail.exe in my firewall.
13/04/01 17:05:42 ** Socket Error # 10060Connection timed out.
May you help me? Thanks!
You can send your sendmail.ini, php.ini and send-mail.php to my email address nikunjbhatt84@gmail.com. I will check all these and reply with suggestion if any.