MyBB Community Forums

Full Version: How-to Fix Email Problem *and keep improved mail functionality*
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey All, I like a few others here had trouble with my PHP mail() function not working correctly. So, I did some digging around and was able to fix my problem, while still keeping all the functionality of the improved mailing system that myBB offers.

The reason that the PHP mail() function was not working for me is because myBB uses "\n" for new line breaks when using the PHP mail() function. I am on a Windows Hosting and it uses stricter mail protocols and requires that new lines be denotated with "\r\n" rather than "\n".

If you are experiencing problems with your mail() function, try these steps to fix it.

1. Open your /inc/mailhandlers/php.php.

2. Find this code
$this->sendmail = @ini_get('sendmail_path');
if($this->sendmail)
{
	$this->headers = str_replace("\r\n", "\n", $this->headers);
	$this->message = str_replace("\r\n", "\n", $this->message);
	$this->delimiter = "\n";
}

3. Replace it with this code
$this->sendmail = @ini_get('sendmail_path');
if($this->sendmail)
{
	$this->delimiter = "\r\n";
}

4. Find this code
if(ini_get('safe_mode') == 1 || strtolower(ini_get('safe_mode')) == 'on')
{
	$sent = @mail($this->to, $this->subject, $this->message, trim($this->headers));
}
else
{
	$sent = @mail($this->to, $this->subject, $this->message, trim($this->headers), $this->additional_parameters);
}

5. Add this code above it
$this->message = str_replace("\n", $this->delimiter, $this->message);

6. Save it and upload it to your website.

It worked for me, maybe it will work for you too. Good luck!
hey thanks for this post, im running MyBB on WINDOWS and I use SMTP instead but I am sure alot will love this helpful hint!

Welcome aboard to MyBB on your first post bro!
You Saved Me Bro.. Thank You. I Was so Frustrated Before. Now I Am Relaxed.
Thank You Again .

Thanks And Regards ,
Yucatans
Do you know of a link to the SMTP protocol documentation that details this requirement?
PHP Email Problem On Windows Hosting Solved!

Thank-you Lyynk for the post. After messing with this email issue for several hours and trying all different kinds of code patches on functions.php, I found your post and like you I am in a Windows Server enviroment.

I applied your changes to php.php and the PHP email functions from myBB started working immediately. Apparently it is a newline conversion issue and your modification to php.php in the mailhandlers solves the problem.

myBB should make this post stand-out to new users, It took me a bit of searching to find this solution.

Thanks again!

-Rich
sorry to ask guys about php mail compared to smtp mail?

any differance between both?

As I have always used smtp mail...
SMTP is generally better, sometimes PHP mail can be picked up by spam filters because the outgoing mail servers do not match the email domain.
(2009-12-15, 10:36 PM)Ryan Gordon Wrote: [ -> ]Do you know of a link to the SMTP protocol documentation that details this requirement?
You are not using PHP_EOL for cross platform EOL detection? From what I remember the root issue was the newline/EOL difference on *nix (\n) & Windows (\r\n) platforms and RFC 2822 would be the specification I would look at fwiw. Worked through a similar issue with phpBB3 last summer debugging 3.0.5 php mail issues on Windows hosts with a developer.
Wow is all I can say. This worked when nothing else seemed to be going my way. Thanks a bunch.

Cynthia