Web Hosting Knowledge Base

Knowledge Base » General Information » How to use PHP mail()?5 min read

How to use PHP mail()?5 min read

In this tutorial, we are going to provide instructions on how to set up a PHP script on your AwardSpace web server and send emails with it.


How Can I Check if the PHP Mail Function is Enabled on my Server?

To see if your web hosting account has PHP mail() enabled, follow these three simple steps:

    1. Create an empty PHP file in your hosting space (e.g. phpmailfunction.php) and place it in the root directory of your web site.


    1. Open the file you have just created, and copy and paste the below code into it:


    if(function_exists('mail')) {
    echo "PHP mail() function is enabled";
    else {
    echo "PHP mail() function is not enabled";


  1. Run the script by accessing the web page in a browser. This should be the URL where you have uploaded your PHP document (e.g. http://yourdomain.com/phpmailfunction.php).


If PHP mail() is enabled on your web hosting server, you will receive a message similar to this:

php mail function 1

If the outlined function does not exist in PHP, you will get the following reply from our server:

php mail function 2

How Can I Test the PHP Mail Function?

On our shared hosting platform, the PHP mail() function only works if the from address is an e-mail address registered within our system. This means you will need to create an e-mail account from the Control Panel, and then use it as a sender in your PHP mailer script.

You can test the PHP mail function on your AwardSpace server by following the below-mentioned process:

    1. Register an e-mail account in our system. If you are unsure how to set up an e-mail address on your server, please review our How to create an email account? tutorial.
    2. Create a new PHP file in your domain directory (e.g. mailerscript.php).
    3. Using our File Manager, open the PHP document you have just created, and insert the following piece of code into it:


    $from='From: Mail Contact Form <you@yourdomain.com>';
    $subject='PHP mail() Test';
    $body='This is a test message sent with the PHP mail function!';
        echo 'E-mail message sent!';
    } else {
        echo 'E-mail delivery failure!';


Note: Make sure you replace you@yourdomain.com with your AwardSpace e-mail address. Otherwise, the mailer script will not be executed properly.


  1. Run the PHP mailer script (e.g. http://yourdomain.com/mailerscript.php) in your favorite Internet browser.


If the test is successful, your browser will display an E-mail message sent! message. You’ll also get an email from our mail server at the specified recipient (to:) address, as illustrated below:

php mail function 3

If for some reason, the above PHP script cannot be executed, you should check your code for any programming/syntax errors or contact our dedicated Support team for assistance.

AwardSpace on Social Media

It's Time to Share Your Story.

Get Free Web Hosting. Start a website, and introduce yourself to the world.

Share This

Share This

Share this post with your friends!