If there’s one thing that irked me about WordPress, which I more or less ignored for months, was the inability to change the “From” address on emails it sent. It’s hard-coded to “wordpress@${sitename}” and when you have some… weird… domain hosters, this can cause problems. I haven’t received comment notification for a few months now as a result.
The problem, in my particular case, is that my hoster is extremely anal about mail relays. If the from address isn’t locally-deliverable, it punts the message with a “relay not permitted”. This is simply foolish, and I’ve already complained, but I have my doubts they’ll change anything.
This could all be extremely easily avoided by letting people change the From address in WordPress. And it’s such a stupidly simple hack. So when I upgraded to the latest WordPress and found it still didn’t allow it, I finally implemented a quick fix and am putting it here for others who face the same irritation.
Index: wp-config.php
===================================================================
--- wp-config.php (revision 1109)
+++ wp-config.php (working copy)
@@ -23,6 +23,9 @@
// to enable German language support.
define ('WPLANG', '');
+// set the from address for mail
+define ('WPFROMADR', '[email protected]');
+
/* That's all, stop editing! Happy blogging. */
if ( !defined('ABSPATH') )
Index: wp-includes/pluggable.php
===================================================================
--- wp-includes/pluggable.php (revision 1109)
+++ wp-includes/pluggable.php (working copy)
@@ -346,8 +346,9 @@
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
$sitename = substr( $sitename, 4 );
}
-
- $from_email = 'wordpress@' . $sitename;
+// why this is hardcoded is beyond me so we'll let it be defined in wp-config.php
+// $from_email = 'wordpress@' . $sitename;
+ $from_email = WPFROMADR;
}
// Set the from name and email
@@ -1562,4 +1563,4 @@
}
endif;
-?>
\ No newline at end of file
+?>
And that’s it. This would be so easy to have implemented upstream, I’m not sure why they haven’t done it already. Now I can set the from domain to something that is hosted on that machine and mails are delivered.