If you want to use Sendmail, install it, dummy!

Right…I must have forgotten to install sendmail, because mail wasn't working for WordPress. First, to verify that sendmail wasn't working I ran this PHP script (thanks to phpeasystep.com)

<?
// send e-mail to ...
$to="me@localhost";

// Your subject
$subject="Test";

// From
$header="from: your name <your email>";

// Your message
$message="Hello rn";
$message.="This is testrn";
$message.="Test again ";

// send email
$sentmail = mail($to,$subject,$message,$header);

// if your email succesfully sent
if($sentmail){
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}

?&gt;<!--formatted-->

That confirmed it. And the fix was easy:

apt-get install sendmail

Doing this exposed a flaw in my hosts file and ZYXware.com had the answer

sudo gedit /etc/hosts

127.0.0.1 localhost.localdomain localhost
127.0.1.1 zyxware01.localdomain zyxware01

If you have a static IP you can replace 127.0.1.1 with your static IP.

So, now mail works from php and, more importantly, WordPress.

[EDIT]
Sheesh…Ubuntu is picky. Here's (almost) exactly what I have for the top half of my hosts file

127.0.0.1    myhostname    localhost.localdomain    localhost
::1    myhostname    localhost6.localdomain6    localhost6
127.0.1.1    myhostname
192.168.1.100    myhostname.mydomain.com

The spaces are actually tabs, I don't know if it matters.

I also don't know what is needed and what is not, but I mimicked this layout on a new server and it worked; the MTA blah-blah service no longer takes forever and sendmail works nice and quickly.
[/EDIT]

Leave a Reply

Your email address will not be published.