PHPBB3 hack to get correct mail headers

 |  8 Comments  |  Posted in Website Software By Aaron

ed. 13Nov12 – This has been tested and amended to be current with v3.11 of PHPBB3 (if you haven’t upgraded your PHPBB3 board to the current version I highly recommend it).

I use PHPBB3 for my niche forums that I own. It’s powerful open source software, and I highly recommend it.

However on certain servers the emails that the PHPBB3 software sends out have incomplete header information. Now in PHPBB3 defense they do specify all the header information in their code, but it’s only on certain server configurations that you need to go one extra step further. Hopefully one day they will add this to their core code.

Here is the problem, the return-path and envelope-from fields are not marked with the forum email address. They are marked with the servers nobody email address.

Return-path: < nobody@server.com >
Envelope-to: user@forumuser.com
Delivery-date: Sat, 04 Apr 2009 22:22:21 +1000
Received: from nobody by server.com with local (Exim 4.69)
(envelope-from < nobody@server.com >)
id 1Lq4tB-0000vz-FW
for user@forumuser.com; Sat, 04 Apr 2009 22:22:21 +1000

What this means is that any bounce messages will go to the server admin (if they are even looking) and not back to the individual PHPBB3 board administrator for them to take action on it.

Unfortunately a core code hack is required to fix this, and this will need to be re-applied each time PHPBB3 has an upgrade. But it’s only a couple of lines of code, so it’s easy.

You want to edit the /includes/functions_messenger.php file…

Find this code (there is 1 instance of this code in v3.11)

	// On some PHP Versions mail() *may* fail if there are newlines within the subject.
	// Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
	// Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space (Use '' as parameter to mail_encode() results in SPACE used)
	$result = $config['email_function_name']($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers);

and make it this code

	// On some PHP Versions mail() *may* fail if there are newlines within the subject.
	// Newlines are used as a delimiter for lines in mail_encode() according to RFC 2045 section 6.8.
	// Because PHP can't decide what is wanted we revert back to the non-RFC-compliant way of separating by one space (Use '' as parameter to mail_encode() results in SPACE used)
	$result = $config['email_function_name']($to, mail_encode($subject, ''), wordwrap(utf8_wordwrap($msg), 997, "\n", true), $headers, "-f" . $config['board_email']);

What that does is add in the 5th parameter (“-f”forumadmin@messageboard.com) to the PHP sendmail function which is for specifying the return-path and envelope-from fields.

Now your output will look like this

Return-path: < forumadmin@messageboard.com >
Envelope-to: user@forumuser.com
Delivery-date: Sat, 04 Apr 2009 22:33:17 +1000
Received: from nobody by server.com with local (Exim 4.69)
(envelope-from < forumadmin@messageboard.com >)
id 1Lq53l-000177-Nx
for user@forumuser.com; Sat, 04 Apr 2009 22:33:17 +1000

and any bounces or PHPBB3 sent email issues will come back to you personally and not your hosting server admin.

Aaron


8 Comments On “PHPBB3 hack to get correct mail headers”


#1 Glenn on on April 6, 2009 at 10:11 am

when applying this hack and using the moderator function to allow a post i get an error

Warning: Unexpected character in input: ‘\’ (ASCII=92) state=1 in /home/domain/forum/includes/functions_messenger.php on line 411

Parse error: syntax error, unexpected T_STRING in /home/domain/forum/includes/functions_messenger.php on line 411


#2 Aaron on on April 6, 2009 at 11:34 am

Sorry about that, I had not put the code into WordPress properly and it had mangled the quotes.

The code is now able to be copy and pasted straight from this blog post.

Aaron


#3 Martin on on April 20, 2009 at 10:07 am

Thanks for the tip


#4 Scott on on September 7, 2009 at 7:27 am

Thanks for documenting this! Anyone aware if a formal feature request is in place to make this a configurable option in phpBB 3?


#5 Aaron on on September 15, 2009 at 7:12 am

@Scott Not sure haven’t looked for ages, but until then at least you have a fix.

Aaron


#6 Aaron Dwyer on on December 29, 2009 at 5:42 pm

I’ve just upgraded to v3.06 of PHPBB3. They still haven’t included this adjustment to the core code.

The fix still needs to be applied, however the core code has changed in v3.06, and there is only one instance of the code to change.

Aaron


#7 John Osmond on on January 30, 2010 at 10:21 am

Hi Aaron. Thanks for the hack it worked great for me.

One thing I noticed is that you have an extra $this->msg where my code has simply $msg. I didn’t change it. I simply added “, “-f” . $config[‘board_email’] to the existing line and did not do a full copy and paste.


#8 system failure on on February 25, 2015 at 11:30 pm

Greetings from Florida! I’m bored to tears at work so I decided to browse your website on my iphone during lunch break.
I really like the knowledge you provide here and can’t wait to take a look when I get
home. I’m shocked at how quick your blog loaded on my
phone .. I’m not even using WIFI, just 3G .. Anyhow,
wonderful site!



Post A Comment

Your email is never shared. Required fields are marked *