简体   繁体   中英

php mail() function not working

I'm getting a 'could not instantiate mail function' error from PHPMailer. From reading around, I understand this to mean that the PHP mail() function isn't working for some reason.

The results of phpinfo() for the mail settings are:

我的 PHP 邮件设置

To me, this means that mail() should work and that port 25 is open. Is that right?

Is there anything else I can check to make this work please? I had a look at the docs for the mail() function, but I couldn't see what exceptions it threw and how I'd print them out to screen. I did a:

mail('name@email.com', "test", "test") or die("Doesn't work");

type test, but that's my error message and I could do with something a bit more helpful.

Grateful for any help on this.

Many thanks

it doesn't mean port 25 is open, it just means that PHP should use port 25 for contacting the SMTP server. You don't state what OS you're on, but note that sendmail would be a unix-only thing, and will fail if you're on Windows.

That list merely show you your current settings. That doesn't mean that they are right. :)

Your localhost is probably not configured to be a mail server. Set the smtp server to a real server than can be reached from your PHP server.

I am probably way off, but check to see if sendmail is installed, maybe it is malfunctioning. This depends on your OS.

The settings from phpinfo() show the PHP is set up to use SMTP but it does not mean that you have an SMTP server set up on the machine. Your error message suggests that one is not setup.

Good luck

My answer would be - don't send emails by calling Sendmail. The sendmail method (or ANY local method) is a mess of pitfalls... and even if you get past those issues, the bottom line is many spam filters (at the places you send mail TO) simply do not like this type of mail.

To provide just a little detail why the sendmail approach is bad, your sendmail daemon is unlikely to be configured to have an SMTP HELO which matches the reverse DNS of your IP address. Your webserver is unlikely to have valid reverse DNS matching a standard hostname. NO reverse DNS at all is bad, as is rdns like 123-123-123-123-static.someisp.com. SpamAssassing will flag such "unconfigured or default reverse DNS" hosts for example.

Fortunately you don't need to understand or fix everything I just said. The much simpler to accomplish (and easier to test/debug) is to GATEWAY your emails through a working SMTP mailserver. To do this:

1a) Install PHPMailer http://phpmailer.worxware.com/ ... OR 1b) Install the PEAR Mail() library http://pear.php.net/package/Mail

Either 1a or 1b will replace the limited "mail()" function in PHP. These replacements support both SMTP, and Authenticated SMTP.

2) I suggest using Authenticated SMTP over plain SMTP. Either works, but with authenticated SMTP you can literally send mail through another mail server just as IF your script were a local email client like Outlook. This has major benefits. For example, if you are a company sending mail, your mail is more likely to be trusted by remote/target mailservers, since your mailserver has a good reputation and (hopefully) proper reverse DNS setup. But if you originate the email off a webserver, you have none of that (and if you use shared webhosting, you will inherit the email reputation of whatever other sites run on your webserver IP.).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM