Basically you have no perfect way of checking if the server is configured to send mails correctly.
You can check the php.ini parameters, for example sendmail_path
, if these represent some correct values. You can try and send a test mail too, but read the manual concerning return value of the function:
Returns TRUE if the mail was successfully accepted for delivery, FALSE
otherwise.
It is important to note that just because the mail was accepted for
delivery, it does NOT mean the mail will actually reach the intended
destination.
Meaning if mail()
returns true, this does not indicate that the server is configured properly. The mail may be accepted for delivery, but the MTA (mail transfer agent) may have problems actually connecting to the internet, or may crash, or ...
You may want to use a third-party-library, which directly connects to a MTA via SMTP and does not use PHPs internal mail
function. This third-party-library may provide a test method to check if this SMTP server is reachable. While this seems to provide more appropriate feedback if it is configured correctly, actually it's limited too. The SMTP server which was provided in this configuration is likely a local one. This one will accept mails to be send, but this does not guarantee that these are sent actually.
This may seem like a dissatisfying answer, but actually the problem is not that serious. Most shared hosters set up their mailing environment correctly. If one has a dedicated server, one can assume that the owner is capable of solving issues with the mail server on ones own.
If you check the sendmail_path
and then send a mail (checking the return value) to a test mail address while outputting the information, that one has to check the mail server configuration, if this mail does not arrive correctly, this should be enough.
Please see also my other posting concerning how one could check if mails are actually being sent or not. The information there applies to PHP as well.