Topic on Project:Support desk/Flow

Enabling email: Unknown error in PHP's mail() function

5
Summary by Ciencia Al Poder

Documentation updated to state that $wgEmergencyContact and $wgPasswordSender should be valid

146.198.223.71 (talkcontribs)

Hi there, I have just installed 1.26.3 on my Hostmonster account. Everything works fine, but I would like to enable emails as well (for notifications, and for password reminders).

If I set $wgEnableEmail = true; and create a new user, I get this error message

Mailer returned: Unknown error in PHP's mail() function.

How can I troubleshoot this please?

I have tried creating a test.php page that sends an email

<?php
print "Sending email...
"; mail("myaddress@gmail.com","My subject","My message body"); print "Sent!
"; ?>

If I load it from my browser, it sends the email OK. The From: field comes as "myHostmonsterAccountName@hostxxx.hostmonster.com". I would like to reproduce what MediaWiki is doing with a minimal PHP script, so I can take it to Hostmonster's tech support.

By the way, how can I test this from WikiMedia without having to create a new user every time?

Thanks a lot for any help! :)

87.123.46.59 (talkcontribs)
146.198.223.71 (talkcontribs)

Thanks, I've seen that, but it's a bit of a sledgehammer solution that I keep as a last resort. My web server can clearly send emails via PHP, so I don't understand why MediaWiki cannot do that. Thanks.

87.123.46.59 (talkcontribs)

This error happens in includes/mail/UserMailer.php. Search the file for the text "php-mail-error-unknown"; at these places the mail function has been used and one of these places is where it failed...

146.198.223.71 (talkcontribs)

OK, thanks, I fixed the problem. I had to set

$wgEmergencyContact = "myHostmonsterAccountName@hostxxx.hostmonster.com";
$wgPasswordSender = "myHostmonsterAccountName@hostxxx.hostmonster.com";

in LocalSettings.php to make it work. I suspect Hostmonster (and probably many other hosting providers) check the headers to beat the spammers, so "From:" and "Return-Path:" need to be genuine, not spoofed.

I am surprised that this problem never came up, I think it should be added to the documentation.

As a minimum, the error message should contain a link to the relevant documentation.

Thanks!