Ubuntu, Sendmail and PHP

Sur­pris­ingly, I hadn’t noticed until just yes­ter­day when I was test­ing out a con­tact form for a web­site under devel­op­ment that my PHP mail() wasn’t work­ing prop­erly. I really should have — Word­Press sends out mod­er­a­tion emails for com­ments, and the absence of those in test­ing should have made me think twice, but it didn’t.

So, PHP and Send­mail weren’t play­ing nice. The default com­mand is sendmail -t -i, if you don’t man­u­ally set sendmail_path in your php.ini con­fig­u­ra­tion, but this wasn’t working.

Unfor­tu­nately, due to some degree of stu­pid­ity in the way things are run, you need to use an absolute path for PHP to find where it is (even if just the com­mand “send­mail” works fine from a ter­mi­nal… like I said, stu­pid), so if you want mail, you have to play by its rules. For no appar­ent reason.

This is all with stock Ubuntu ver­sions of Apache2 and PHP, by the way — the stu­pid­ity may go away if you do-it-yourself, but I’m kind of doubt­ing it.

Any­way, assum­ing you’ve got send­mail (or an MTA which pro­vides send­mail hooks — I’m actu­ally using post­fix here) installed, you can sim­ply set this in your php.ini, restart Apache (using apache2ctl restart from a root account), and all should be working:

sendmail_path = /usr/sbin/sendmail -i -t

Bingo!

Tags: ,

posted on Monday, March 28th, 2005 at 11:37 am by Josh, filed under Geek, PHP.

7 Responses to “Ubuntu, Sendmail and PHP”

  1. Ronan says:

    Wow, that’s a really use­ful tip. I can’t believe one has to spec­ify a sta­tic path to send­mail within the php.ini. Mad.

    I’ve still got a few issues with localhost.localdomain on php mail, but this was very good to know.

  2. […] cribbed from here and here. Active Direc­tory Aging Baby Bass Birth­day Blogs Books Change Choices Cold […]

  3. John says:

    Just a lit­tle com­ment: PHP requir­ing full path to send­mail (actu­ally, any other binary) actu­ally makes per­fect sense:
    when run­ning send­mail from a ter­mi­nal the binary is found by look­ing into $PATH. PHP can’t count on that being defined for itself, thus it needs the full path to the binary (just as you would need to type if you hadn’t a prop­erly defined $PATH).

    Hope this clar­i­fies a lit­tle bit.

  4. pascal says:

    Won­der­ful,
    I used a full path to /usr/sbin/ssmtp, it worked with a com­mand shell but not with a script. It’s really stu­pid!
    thank you

  5. Matt says:

    Superb, thanks for that, that saved me hours of headache!

    Matt

Leave a Reply