Wordpress Logo

Did you know that WordPress sends you emails when you get a new blog comment? I didn’t – because it has never worked for me. But once I knew it was supposed to email me I looked into it and found a fix.

Setup: My setup is running WordPress.org on a Ubuntu 9.04 box called Butterfree with sendmail installed.

The problem was that the Return-Path header in my outgoing mails wasn’t valid which caused some mail recipients to reject the mail, while other less picky ones, accepted the mail fine (e.g. gmail). The Return-Path header that sendmail was using looked something like this:

Return-Path: <www-data@butterfree.bitvolution.com>

I found this by changing the admin email from the one that didn’t work to a gmail one, then posting a test comment on one of my posts. Then I waited for the email to arrive in gmail and selected “show original” from the gmail interface. A quicker way is to check the entries in /var/log/mail.log.

In order to fix the issue, I configured the return path in emails sent from WordPress (i.e. PHP) to something different using the -f parameter for sendmail:

sudo emacs /etc/php5/apache2/php.ini

Find the sendmail_path and uncomment it and add the -f flag:

; -f will set the "return-path" headers.
sendmail_path = /usr/sbin/sendmail -i -t -f sendmail@bitvolution.com

Doing this solved this issue so I now get email about new comments.

My fix feels a bit of a hack. I would be interested in how to solve this problem the right way, so let me know if you can give me some advice. For example, perhaps I should have done something with my DNS settings for my domain?