Email Testing
It can be frustrating when a PHP script sends an email and it doesn't arrive in the mailbox where it is expected.
There are many points to check. Some are: Was it a valid email address? Did filters catch it? Is it just slow in arriving?
This article provides a script to check just one point — whether the server actually sends email.
Customize this script with an email address for testing. Put it on your server. Type its URL into your browser. The script will run the PHP mail() function to sent an email to the email address you specified.
<?php // Test Email // Version 1.0 // November 18, 2024 // Will Bontrager Software, LLC // https://www.willmaster.com // The email address, email subject, and email content to send the test email to. $EmailAddressForTest = "name@isp.com"; $Subject = "The email test"; $Content = "AN Email test from {$_SERVER['PHP_SELF']}"; // No other customization required. // Sending the email. mail($EmailAddressForTest,$Subject,$Content,"From: $EmailAddressForTest"); ?> -Mailed-
Now, see if the email arrived. Allow sufficient time for the email to transport and get dropped off in your mailbox.
If no email arrives in the mailbox, try testing a different email address, one that is not on the same server as the email that was just tested.
If no email arrives for any email address you test, then it may well be the server that is not sending email. (That would be the server where the email testing PHP script is installed.) The reason could be for any number of reasons — server's IP address blacklisted, server doesn't allow the PHP mail() function to be used, hosting company is filtering out your email, … . At this point, it would generally be time to ask support for input. They may need a copy of the script.
If email arrives to at least one of the tested email addresses but does not arrive at other email addresses, then the server is sending the email. Instructions about what exactly needs to be done now about the email that did not arrive is outside the scope of this article. The actions probably will include testing for spam filters and verifying that each email address works when sent from a different emailer. Also check if the sending IP address is at a service that the destination server consults.
Debugging email can be frustrating. This article provides a script to test if one aspect is working as it should.
(This content first appeared in Possibilities newsletter.)
Will Bontrager