Jump to content

mail() failed.


jane

Recommended Posts

I used the following code to get email from an html form.<?php$to="someone@yahoo.com";$subject=$_REQUEST["subject"];$email=$_REQUEST["email"];$message=$_REQUEST["message"];mail($to, $subject, $message, "From: $email");echo "Mail sent";?>It came out the 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 E:\Documents and Settings\My Documents\My Web Pages\phpfile.php on line 160I came across this problem before. Then I downloaded a free SMTP server from www.softstack.com, and the mail went through. Now, I came up with the same problem again. I turned on the free SMTP, it still did not work. I don't have a commercial web server, all my files are under localhost. I downloaded the php, apache, and mysql from wamp5. So do I need to check some .ini file for this? Or is it better to use asp for sending email?Thank you very much.

Link to comment
Share on other sites

Well, it's really better to use a commercial server. Some home ISPs block the outgoing mail port and do not allow you to send mail. You might want to send yourself a test email when you get this issue solved to see if they are really going through. In terms of scripting languages, I prefer PHP's functionality over ASP's, but that's a personal preference.Obviously the error means that PHP cannot communicate with the SMTP server. First step is to make sure the SMTP server is running and is accepting connections. You can test this yourself:Click on Start -> Run and type in "cmd" and press enter. In the command prompt, type "telnet localhost 25" (without quotes). If you do not receive an error, then your computer is accepting connections on port 25 (which is the standard SMTP port). If you get a connection error, then the SMTP server is not working correctly.The SMTP and smtp_port options are set in php.ini. Do a search on your computer for php.ini (it is probably in the Windows directory), and then do a search inside php.ini for "smtp". If you have the smtp server installed locally, then the settings "localhost" for the server and 25 for the port should be fine, unless you changed the setup in the smtp server. You may need to check the settings there as well. If you aren't able to figure it out on your own, you might want to contact whoever made the smtp server and try to find out if there are any issues using it with PHP.

Link to comment
Share on other sites

OK. Try opening the Free SMTP Server application, and in the status bar on the bottom you should see it say "Waiting for connections on port #25". When you see that, try your PHP application and see if it still fails.If you're still having problems, you can try contacting softstack here:http://www.softstack.com/contact.htmlTell them about the issues you are having and what you've already tried. Maybe copy and paste the address of this thread. They might have some more information, and it looks like they do offer technical support for this product.You said that it was working before, and now it doesn't work. What changed between then and now?

Link to comment
Share on other sites

I tried your suggestion, still failed with the same error message. The mail() did work after I installed SMTP free server. Now it does not work. I forgot what I have done between then and now. I just sent an email reporting my problem to the softstack link you gave me. Hope the problem would be resolved soon.Thank you very much.

OK. Try opening the Free SMTP Server application, and in the status bar on the bottom you should see it say "Waiting for connections on port #25". When you see that, try your PHP application and see if it still fails.If you're still having problems, you can try contacting softstack here:http://www.softstack.com/contact.htmlTell them about the issues you are having and what you've already tried. Maybe copy and paste the address of this thread. They might have some more information, and it looks like they do offer technical support for this product.You said that it was working before, and now it doesn't work. What changed between then and now?
Link to comment
Share on other sites

The technical support at Softstack asked me to try their First SMTP Server. I tried but still got the same error. I open the cmd window,typed "telnet localhost 25", it came out: "220 Welcome to ESMTP Server".typed "mail from sb@yahoo.com, came out "250 Ok"typed "rcpt to sb@yahoo.com, came out "250 Ok"typed "data", came out "354 Enter mail, end with "." on a line by itself"typed "subject: test email This is just a test." came out "250 Ok"typed "quit", came out "221 Closing transmission channel Connection to host lost"The mail() did work previously after I installed SMTP server, now it does not work. Between then and now, I upgraded the McaFee Security Center, upgrade IE from 6 to 7 beta. But I am now only using firefox browser since it's faster. I doubt the problem might come from Mcafee. But how to resolve it? Thank you very much.

Link to comment
Share on other sites

McAfee might have a firewall or a feature that blocks programs from accessing an SMTP server. They might do that to try and keep people from getting a spam server installed on their machine. Maybe try poking around the control panel and see if you can see anything, or maybe try a McAfee forum and see if you can find an answer there.

Link to comment
Share on other sites

Thank you very much. Today, strange enough. All the php mail() went through with the original free SMTP server. I did not change anything, except once in a while Mcafee did some automatic upgrades.The only exception is in <?php$to="someone@yahoo.com";$subject=$_REQUEST["subject"];$email=$_REQUEST["email"];$message=$_REQUEST["message"];mail($to, $subject, $message, "From: $email");echo "Mail sent";?>$to and $email cannot be exactly the same email address, like both are someone@yahoo.com. If both are the same, the mail still went through without error, just I cannot receive the self-mailed mail in my yahoo account. If one is a@yahoo.com, another is b@yahoo.com or b@comcast.net, the mail would go through, and I could get all the mails in my yahoo account.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...