Why am I getting a "Failed to connect to mailserver" error in this email script?
I have encountered an error:
Warning: mail() [function.mail]: Fai开发者_StackOverflowled to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\works\test\registration-code3.php on line 56
Here is my php.ini
:
define_syslog_variables = Off
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = postmaster@localhost
How can I fix this?
Based on what you've shown us, particularly this bit:
C:\works\test\registration-code3.php
Leads me to believe your testing some script on your local system. If this is so and you haven't installed and set up a mail server, then of course its not going to work. You require a MTA to actually send the email, PHP just hands off to it.
If you've simply installed XAMPP then you don't have a working MTA to send through without some real work ahead of you.
If you must send email from your dev machine in this fashion, I recommend picking and using a script like Swiftmailer which will allow you to easily use a mail server hosted elsewhere - like your ISP or even google.
It looks like your Windows machine don't have SMTP server on the port 25. I am guessing that it is your development machine. Instead editing your ini file you can try some other SMTP servers, for instance, the one your ISP provided you with.
Try to add the following code to the top of email script:
ini_set("SMTP","mail.domain.com");
ini_set("smtp_port","25");
ini_set('sendmail_from', 'Email@domain.com');
精彩评论