Skip to content
mybox Help Center

Help sections

  • Getting Started
  • Account & Billing
  • Domains & DNS
  • Hosting & Servers
  • Email
  • Security & SSL
  • WordPress & CMS
  • Grow Online
mybox.com All services operational
/

Language

  • English
  • Română
  • mybox panel
  • Webmail
Start free
/
  • Getting Started
  • Account & Billing
  • Domains & DNS
  • Hosting & Servers
  • Email
  • Security & SSL
  • WordPress & CMS
  • Grow Online
  • Help Center
  • mybox.com
  • English
  • Română
All services operational Start free
  1. Help Center
  2. Email
  3. Email Troubleshooting
How-to Email

How to Test the PHP mail() Function Using a Simple Script

Updated June 2, 2026 1 min read
On this page
  1. Step 1: Create the test file
  2. Step 2: Add the test script
  3. Step 3: Run the test
  4. Expected result
  5. Notes

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).

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 = ‘sender@example.com’; $recipient = ‘recipient@example.com’; $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 <?php at the beginning and ?> at the end of standalone PHP files
  • Make sure sender and recipient addresses are valid to avoid delivery issues

Was this article helpful?

Didn't find an answer?

Our support team is here for you 24/7 – write to us and we will help you sort it out.

Helpdesk 24/7 Open a ticket in the mybox panel mybox panel Log in and manage your services

On this page

  1. Step 1: Create the test file
  2. Step 2: Add the test script
  3. Step 3: Run the test
  4. Expected result
  5. Notes

Related articles

All in Email Troubleshooting
Problem Email Troubleshooting How to Fix SMTP Authentication Failed Errors in Email Clients An SMTP authentication failure occurs when an email client cannot verify your credentials with the outgoing mail server. This typically prevents you… 2 min read Explainer Email Client Configuration OAuth Sign-In Loops in Outlook, Apple Mail, and Thunderbird: Causes and Fixes An OAuth sign-in loop occurs when Outlook, Apple Mail, Thunderbird, or another email client repeatedly opens a sign-in window, rejects credentials that… 4 min read Explainer Email Client Configuration Email Client Keeps Going Offline or Disconnecting: Causes and Fixes If Outlook, Apple Mail, Thunderbird, or another email client keeps switching to offline mode or losing its connection, the cause is usually… 3 min read
mybox

Modular web hosting – free out of the box, modular to grow.

Help sections

  • Getting Started
  • Account & Billing
  • Domains & DNS
  • Hosting & Servers
  • Email
  • Security & SSL
  • WordPress & CMS
  • Grow Online

mybox

  • mybox.com
  • mybox panel
  • Webmail
  • Helpdesk 24/7
© 2026 mybox 1,680 articles