If you want to check whether the PHP mail() function works correctly, you can upload a simple test file to your server using FTP (for example FileZilla).
Table of Contents
Step 1: Create the test file
Upload a file to your /public_html directory.
Example filename:
phpmail.php
Step 2: Add the test script
Paste the following code into the file and replace the sender and recipient email addresses with your own values: <?php $sender = ‘[email protected]’; $recipient = ‘[email protected]’; $subject = “Test message”; $message = “PHP mail function test”; $headers = ‘From:’ . $sender; if (mail($recipient, $subject, $message, $headers)) { echo “Message sent successfully”; } else { echo “Error: Message could not be sent”; } ?>
Step 3: Run the test
Open the file in your browser:
http://yourdomain.com/phpmail.php
Expected result
If everything is working correctly:
- Message sent successfully
If there is an issue:
- Error: Message could not be sent
Notes
- Ensure the PHP
mail()function is enabled on the server - Some hosting providers require valid SMTP configuration even if
mail()is available - Always include
<?phpat the beginning and?>at the end of standalone PHP files - Make sure sender and recipient addresses are valid to avoid delivery issues