Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I recently implemented a comment area on my website and tried to get the email notification functionality to work. It doesn't seem to want to send email notifications when new comments are made. Just to see if PHP can send emails, i tried to reset the password (because you'll get a new password via mail), and i then got the message:

The e-mail could not be sent. Possible reason: your host may have disabled the mail() function

I've checked the checkboxes in Settings -> Discussion, and the email is valid, so it's not a setting issue. I tried to create a php file and send using mail(), and it sent successfully. So there must be something weird going on with Wordpress.

Any ideas?

share|improve this question
    
Please provide debugging information –  s_ha_dum Apr 8 '13 at 15:12
add comment

3 Answers

Step by step: First find the file where the error message appear. I use Notepadd++ and the [CTRL]+[f] command to search in files. It is a good idea to search only the first few words of the error message, because some error messages are combined of different messages.

Your error message appear in wp-login.php and holy luck, only there. So let's have a look why this error could occure.

if ( $message && !wp_mail($user_email, $title, $message) )

There are two conditions. $messagehave to be true (not an empty string, not false, not null, etc). And wp_mail() shouldn't return false.

One line above, there is a filter $message = apply_filters('retrieve_password_message', $message, $key);, so it is possible that a plugin (or theme) use this filter and returns a value that is not true (empty string, false, null, etc.).

But it is much easiere to check if wp_mail() is working or not. Write a small plugin to send a test mail to yourself:

<?php
/**
 * Plugin Name: Stackexchange Testplugin
 * Plugin URI:  http://yoda.neun12.de
 * Description: Send me a test email
 * Version:     0.1
 * Author:      Ralf Albert
 * Author URI:  http://yoda.neun12.de
 * Text Domain:
 * Domain Path:
 * Network:
 * License:     GPLv3
 */

namespace WordPressStackexchange;

add_action( 'init', __NAMESPACE__ . '\plugin_init' );

function plugin_init(){
    $to      = 'your-email-adress@some-domain.tld';
    $subject = 'Testemail';
    $message = 'FooBarBaz Testmail is working';

    wp_mail( $to, $subject, $message );
}

(This is PHP5.3 code. If you are running PHP5.2, remove the namespace things)

The plugin should send a testmail immediately after activation. If not, calling some backend pages (e.g. dashboard) should do it.

If the testmail does not arrive, then you probably have an issue with wp_mail(). So turn on debugging:

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors',1 );

Put this code into your wp-config.php and retry sending yourself a testmail. Now you should get some error messages and they also should be logged into wp-content/debug.log (The debug log can grow very large if there are more errors caused by plugins and/or themes).

At this point, you got good informations if wp_mail() fails and if so, why. If wp_mail() work correctly and the testmail arrived, go back to top and find out why $message is not true.

If you have issues with wp_mail(), so keep in mind that wp_mail() does not use PHPs mail() function. WordPress use a PHP class (PHPMailer). Maybe you just need a pluin to use SMTP instead of sendmail. Or the problem is located at another place. We don't know. You have to investigate.

share|improve this answer
    
Yeah i tried digging into the core and it also lead me to PHPMailer, and it actually does use php's mail(). At least in some cases (see line 732 in wp-includes/class-phpmailer.php. I don't have access to the ftp atm but i will try your suggestions as soon as i can. Surely this must lead me somewhere. Thanks a lot! –  qwerty Apr 8 '13 at 17:52
    
I tested wp_mail() and it seems to work fine, i received the mail as expected. WP still wouldn't send the comment/password-reset emails though, and i didn't get anything in the log file (it wasn't created), so i tried installing an SMTP mail plugin and set up a new email account for Wordpress. It works now but i still don't understand why it couldn't send before. Thanks! –  qwerty Apr 9 '13 at 7:05
add comment

That's a typical issue with some web hosts who disable or restrict php mail. Try a plugin to use your hosts SMTP server instead. See http://wordpress.org/extend/plugins/search.php?q=mail+smtp

share|improve this answer
    
PHP's mail() works fine though, i tried it. I also mentioned it in the question. –  qwerty Apr 8 '13 at 17:44
    
I also said "restrict" php mail. Try an SMTP plugin. –  songdogtech Apr 8 '13 at 18:02
    
My bad. SMTP works but i still don't understand why it failed before, as both php's mail() and wordpress' wp_mail() both worked fine. –  qwerty Apr 9 '13 at 7:09
add comment

I ran into this today; in my case the situation happened because the server's hosts file has the same domain name of the email address, pointing to localhost. The mx record points to a different server, but the hosts file is overriding DNS and WP is trying to deliver the email locally. Removing the domain from the hosts file and restarting sendmail resolved this issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.