开发者

Test for PHP mail Functionality without calling mail

开发者 https://www.devze.com 2023-01-26 07:37 出处:网络
Aside from actually attempting to send an email with mail() and checking the returned value for a failed result, is it possible to \'feature detect\' whether mail() will work?

Aside from actually attempting to send an email with mail() and checking the returned value for a failed result, is it possible to 'feature detect' whether mail() will work?

If it is not possible, what would be common tell-tale signs that it is likely to fail?

Some scenarios:

  • Giving site administrators warning about email configuration errors
  • Providing alternate workflow开发者_运维百科s to module users where mail is not available
  • Getting around framework mail wrappers that don't suppress errors

EDIT: Some clarification - I'm not trying to test for unreported errors (upstream delivery failures, or any condition that PHP returns true from mail()). Basically I'm looking for one or more simple tests that can be performed purely in PHP (or a system call from PHP) that would at least give you a heads-up that called mail() is not safe.


It isn't possible to programmatically check. Most of the time on mis-configured servers, mail() will appear to succeed just fine, but the message will be sitting in a queue somewhere on the server.

As cdhowie said, even if it did work, you could have other problems upstream.

What you could do is fire off a test e-mail to one of your servers with a random key of some sort in the subject line. On your server, have some code read these test e-mails and then add them to a database. Build a simple script that returns a simple yay/nay whether or not the test e-mail was successfully received. isitthereyet.php?key=ASDFASDFASDF

That's probably overkill though for what you want, but the best solution I can think of.


Do you just want to check if the mail() exists so it doesn't return undefined function? You could use function_exists.

0

精彩评论

暂无评论...
验证码 换一张
取 消