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:
Solution:
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
- Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:
- Enable “ssl_module” module in Apache server:
- 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: sender@gmail.com' . "\r\n" . 'Reply-To: sender@gmail.com' . "\r\n" . 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=iso-8859-1' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); 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, sender and reply-to address. 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
good description sir....
ReplyDeleteFailed to connect to mailserver at "" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
ReplyDeleteHi Snatosh,
ReplyDeleteYou need to comment smtp_port = 25 as describe above. please make double sure about it. and restart wamp. it should work :)
Thanks,
Arpan
will it work in windows 8
ReplyDeleteHi. i followed all the steps.but it is still not working
ReplyDeleteif you are getting Socket Error # 10060Connection timed out
Deleteplz change sendmail.ini from
smtp_ssl=ssl
to
smtp_ssl=none
and it will work on Win 8 too!!
I think it's not related to OS.. It should work.
ReplyDeleteHave you facing any error? Plz "Enable these log file settings if you don’t get able to send email using sendmail" as describe in above
hi... i have win8 and get this type of error so what should i do
ReplyDeleteFailed to connect to mailserver at "" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Hi Ram,
DeleteI think you should double check following step.Please check it and let me know.
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"
hi the mail script work but i didn't receive any mail
ReplyDeleteHi yugal,
DeletePlease check in span. if scrip run, email is in your inbox or spam folder
Thanks,
Arpan
Hello...... Sir please help me to fix it out.
ReplyDeleteI have used each and every step which you have been described above but still getting "Email sending failed" error.
so please help me!!
Thanks in advance :)
Hi Vipin,
DeleteWhat is your wamp's PHP version?
I am also getting the same problem my wamp's PHP version is 5.3.10
Deleteplz check all steps again..once you done with perfet installation you should get message "Mail Sent".
Deletehello Sir,
ReplyDeletePHP version- 5.4.16
wamp- 2.4
i had gone through all the above steps, and no error message or warning are showing except "Mail sent"(this message in if part of mail()), but i didn't receive any mail in any folder.
Kindly share ur ideas
Thanks
Hi Avinash,
DeleteCan u plz let me know your sendmail_path? and what's value of it?
my php.ini looks like:
ReplyDeletesendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t -i"
Watch the extra "\ and -i" at the begin and end of the line
; sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
Had to comment this out ie put a ; in front of the line.
Finally i've got it working, tnx for info
Thanks for your comment.. it will help to others..
DeleteThis script is running but i didn't receive any mail ..please help me
ReplyDeletescript is running and no error means working.. plz check your spam folder and plz do debugging and let me know in detail where exactly it stopped executing so i can help you...
DeleteThis comment has been removed by the author.
ReplyDelete( ! ) Warning: mail(): Failed to connect to mailserver at "" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\sendmail.php on line 10
ReplyDeleteCall Stack
# Time Memory Function Location
1 0.0010 141144 {main}( ) ..\sendmail.php:0
2 0.0010 142088 mail ( ) ..\sendmail.php:10
i am using 32 bit window 7 with wamp server of 32 bit
ReplyDeleteComment your smtp_port. please verify below code as smtp_port should be commented.
ReplyDelete[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25
what we have to do if we want to upload this script online then what will be the change in this script please reply must....
Deletesame process you should follow...
DeleteI have run this code . it shows email sent but i didt receive any mail ?
ReplyDeleteEmail sent event only fire when everything is fine and email should sent. plz chk in spam folder
DeleteAny one please Tell me the solution.
ReplyDeleteEmail sent event only fire when everything is fine and email should sent. plz chk in spam folder
Deletei have checked my spam too i didt get any mail
Deleteplz chk your error.log file in your sendmail folder. and let me know if you got any error?
DeleteThanks, worked like charm...
ReplyDeleteThanks for your comment..
DeleteHi I am getting this error: Socket Error # 10060Connection timed out. Any suggestion what I need to change?
ReplyDeleteif you are getting Socket Error # 10060Connection timed out
Deleteplz change sendmail.ini from
smtp_ssl=ssl
to
smtp_ssl=none
and it will work for you..
----DEBUG-----
ReplyDelete14/04/13 00:24:43 ** --- MESSAGE BEGIN ---
14/04/13 00:24:43 ** To: boxygillett@live.co.uk
14/04/13 00:24:43 ** Subject: Testing sendmail.exe
14/04/13 00:24:43 ** X-PHP-Originating-Script: 0:send-mail.php
14/04/13 00:24:43 ** From: sender@gmail.com
14/04/13 00:24:43 ** Reply-To: sender@gmail.com
14/04/13 00:24:43 ** MIME-Version: 1.0
14/04/13 00:24:43 ** Content-type: text/html; charset=iso-8859-1
14/04/13 00:24:43 ** X-Mailer: PHP/5.4.12
14/04/13 00:24:43 **
14/04/13 00:24:43 ** Hi, you just received an email using sendmail!
14/04/13 00:24:43 ** --- MESSAGE END ---
14/04/13 00:24:44 ** Connecting to smtp.gmail.com:465
14/04/13 00:24:44 ** Disconnected.
14/04/13 00:24:44 ** Disconnected.
14/04/13 00:24:44 ** Disconnected.
14/04/13 00:24:44 ** Socket Error # 10060Connection timed out.
----EORROR-----
14/04/13 00:24:44 : Socket Error # 10060Connection timed out.
When I change ssl to none as stated above all my page does have loading symbol going round and round and round nothing happens what so ever
Deletein the apache php ini and also the php ini I have everything ; out apart from the path which is like this...
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t -i"
Other than that everything is exactly how you said above yet a change ssl to ssl and I just get message failed and get the errors above.
Help please :'(
Can you please replace your code :-
Delete$headers = 'From: sender@gmail.com' . "\r\n" .
'Reply-To: sender@gmail.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
With below code.(don't forget to change email)
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: my website name ' . "\r\n";
Sir, i did all the above steps as you have mentioned. but still i get the following 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()"" ......Please help me out..
ReplyDeleteit seems Below code is not commented:-
Delete[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25
Can you plz comment it as mentioned in above code.
i tried this but got same 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:\wamp\www\test\send_mail.php on line 10"
Deletesir send mail folder and php send file is in same folder ...
ReplyDeletebecause mail cannot be send msg
hello sir, i am not getting mail spam n inbox
ReplyDeletei am not getting error.log file in sendmail.php.........any other solution sir plz
ReplyDeletehave u got any error/warning?
Deleteno sir......but not getting mail on gmail
ReplyDeletePlz check your spam folder and plz do debugging and let me know in detail where exactly it stopped executing so i can help you...
Deleteplz chk your error.log file in your sendmail folder. and let me know if you got any error?
This comment has been removed by the author.
ReplyDeleteHello Sir please help me to fix it out.
ReplyDeleteI followed each and every step which you have mentioned above but still getting am "Email sending failed" error.
i am using php version 5.5.12
so please help me!!
Thanks in advance :)
Can you please let me know the error from the error log file? so i can help you...
Deletesir i have problem Email sending failed help me
ReplyDeleteCan you please let me know the error from the error log file? so i can help you...
Deleteerror occur Email sending failed
ReplyDeleteCan you please let me know the error from the error log file? so i can help you...
Deletethnx a lot ..it is a great help for person like me who is a beginner in web development :)
ReplyDeleteThank you fro your comment!!!
DeleteIts working great.. Very Helpful.. I got email from my localserver.. Thanks a lot..
ReplyDeleteThank You for your comment...
Deleteits working great...
ReplyDeleteThanks for comment about Send email from localhost/WAMP
DeleteHi I am getting this error: Socket Error # 10060Connection timed out..plx help
ReplyDeleteHi Shahzad,
DeletePlease make following change
In sendmail.ini replace below line from
smtp_ssl=ssl
to
smtp_ssl=none
If it can't resolve your issue then
Can you please verify SMTP port in your sendmail.ini file. Also compare the settings again.
Good job. It really helps me.
ReplyDeleteThanks for your comment!!
DeleteError On
ReplyDeleteEnabling “ssl_module” module in Apache server
Enabling “php_openssl” and “php_sockets” extensions for PHP compiler
plzz help
I think something went wrong with your configuration
DeletePlease open php.ini manually and make below changes
Find below line and remove semicolon from above line
;extension=php_sockets.dll
;extension=php_openssl.dll
and restart WAMP
If you still get same error please Once again check all configuration properly and change accordingly
Hai,
ReplyDeleteam using
windows 8
WampServer Version 2.5
i got the following 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:\wamp\www\test\send_mail.php on line 10
i read previous comments for this issue to change the code in php.ini
[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"
i tried this. even though i got the same error.. plz help me to solve the issue!
Hai,
ReplyDeleteNow i just recheck the steps which you said above and restart the wamp. i got the message Email sent. But i did n't get any mail. even i checked my spam folder too, i did't get any mail.
Hello
ReplyDeleteSir..
Its Not Working...
( ! ) 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\Mail\mail.php on line 10
Call Stack
# Time Memory Function Location
1 0.0010 365816 {main}( ) ..\mail.php:0
2 0.0010 366488 mail ( ) ..\mail.php:10
Email sending failed
Hello,,
ReplyDeleteSir,
My program doesn't work mail function. It show the error like
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:\wamp\www\yedu\mail.php on line 16
...
plz help what can i do ?
Sir, i am getting error "Connection Closed Gracefully" in error.log file
ReplyDeletewhat is the problem ?
HI,
DeleteSendmail has to be run as an administrator. Please follow below steps :
1 Right click on sendmail.exe
2 Properties
3 Compatibility
4 Change the configuration for all users
5 Execute as Windows XP or whatever you have
6 Execute as adminitrator
And save :)
Hi. Same error "Connection Closed Gracefully". I am sing Win10 and wamp. In #5, there is no compatiblilyt mode for Win10. and where is #6?
ReplyDeleteWhen you click on sendmail.exe, you can see an option "Run as administrator". So first you should click on it and then you should follow step 1 to 5. I think OS doesn't matter here.
DeleteEmail sending failed
ReplyDeleteCan you please give me exact error which you are getting?
DeleteConnection Closed Gracefully.
ReplyDeleteDid you get this message? At which step?
Deletei will get a one error that is Warning: mail(): Failed to connect to mailserver at "localhost" port 587, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in
ReplyDeletePlease check your configuration. It's only problem of configurations.
DeleteHello Sir,
ReplyDeleteKindly Helps to create a Php mail for sending and receiving is very diificult .
Pls help for give correct code
Can you please give me an more details. what error you are getting? what you have tried?
Deleteemail sending failed
ReplyDeletehello sir, i am not getting mail spam n inbox
ReplyDeletethis is error.log file
16-04-27 20:01:06 : Socket Error # 11001Host not found.
16-04-27 20:01:14 : Socket Error # 11001Host not found.
It 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 reasons for this error.
Deletei followed same steps but still i m getting error
ReplyDeleteFailed to connect to mailserver at "" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\cind.php on line 8
Email sending failed
This comment has been removed by the author.
Deleteit seems Below code is not commented:-
Delete[mail function]
; For Win32 only.
; http://php.net/smtp
;SMTP =
; http://php.net/smtp-port
;smtp_port = 25
Hello Sir please help me to fix it out.
ReplyDeleteI followed each and every step which you have mentioned above but still getting am "Email sent successfully.. but not getting mail on gmail i also check in spam folder..
plz sir help me.
i am using php version 5.5.12 and os windows 10
If the path to the sendmail.exe contains “space” (for example, “C:\Program Files\PHP\sendmail\”) then PHP would not be able to locate it. So, either store the sendmail.exe at a “non-spaced” location/path OR write the path in DOS style “C:\Progra~1\PHP\sendmail\” in the php.ini (sendmail_path = "C:\Progra~1\PHP\sendmail\sendmail.exe -t -i").
Deletethanks was very helpful. what of using yahoomail for the smtp authentication.
ReplyDeleteI can't get email even there is no error.Help me!!!
ReplyDelete