A

Check mail sending capabilities of your webhost

I have seen numerous discussions and queries on subjects which varies from simple plugins to fully complex scripts, all being blamed by people that they didn’t work but they are unable to receive an expected email. And most of the time it has to do with the webhost. Several webhosts disable the mail sending capabilities […]

mail

I have seen numerous discussions and queries on subjects which varies from simple plugins to fully complex scripts, all being blamed by people that they didn’t work but they are unable to receive an expected email.

And most of the time it has to do with the webhost. Several webhosts disable the mail sending capabilities on their shared hosting account so as to avoid spam being send from their server.

But before you ran into your webhost blaming for the cause, I would say how about we check whether the issue is really the webhost?

Just create a simple php file with the following content and upload it to the root of your hosting account and access it in browser as example.com/testfile.php

<?php

// Your email address
$email = "xyz@gmail.com";

// The subject
$subject = "testing mail sending capabilities";

// The message
$message = "test";

if ( mail($email, $subject, $message, "From: $email") )
	echo "The email has been sent!";
else
	echo "Error sending email!";

?>

Replace the email address with your own email address on line 4.

This code snippet tries to send a mail to the email address specified on line 4 and if the mail was successfully sent, you will see the message “The email has been sent!” else you will see the message “Error sending email!”.

If you are using WordPress, I would suggest using this snippet which checks for both PHP’s mail() function and WordPress’s wp_mail() function as wp_mail function is pluggable and may be some plugin has plugged it and only may be that is failing and nothing is wrong at the web host side. But make sure that you place the file in WordPress root and not domain root as it will load the WordPress environment and then try to send mail by wp_mail().

<?php

// Your email address
$email = "xyz@gmail.com";

// The subject
$subject = "testing mail sending capabilities";

// The message
$message = "test";

// load WP now
require('wp-load.php');

if ( mail($email, $subject, 'mail: ' . $message, "From: $email") )
	echo "The email has been sent using the PHP's mail() function.";

if ( wp_mail($email, $subject, 'wp_mail: ' . $message, "From: $email") )
	echo "The email has been sent using the wp_mail() function.";

If you need any help, then feel free to leave a comment here and I will try to help.

Alternatively, you can also hire me.

10 responses to “Check mail sending capabilities of your webhost”

  1. Chethan says:

    Cool Post! 🙂

  2. TechChunks says:

    Cool idea to test your host’s email sending capability. 🙂

    • Ashfame says:

      Yeah! I was working on a client’s site and creating the code to check the mail sending capabilities and then I thought why not share this with everyone on my blog. 🙂

  3. Nicolas says:

    Indeed, the code snippet for testing wp-mail is cool!
    On my host, both tests (mail and wp-mail) are positive ; still no mail received in my mailbox. According to you, what is the next step to understand and debug the situation?
    Thanks

    • Ashfame says:

      Check if something in functions.php file under your theme or any plugin that may be plugging the default definition of the wp_mail() function. I know it can be hard for you to trace it but look for function definition of wp_mail()

      If that doesn’t help, try getting in touch with your host. They might be able to help by checking the log files.

  4. Tw3x says:

    Nice tutoriel tnx for sharing

  5. uday says:

    Hi there…i used example and uploaded to my web-host but its say message has been sent but actually im not receiving any messages i.e. hotmail..can u help with this please thanx.

    • Ashfame says:

      Can you receive emails on other accounts such as gmail or yahoo? Anyone of them?
      If yes, then it might be putting them in spam folder or filtering them out. No problems with your webhost.