PHP mail() issue

Posting here as I thought someone here might have seen this behavior…

When sending mail via PHP's mail() function, ~10% of my user's receive the email malformed, consistantly (i.e. not a random issue with mail() but perhaps a configuration issue with mail that is causing certain mail providers to display it incorrectly?)

Here is what these user's are seeing in the body of the email for some reason:

Reply-To: "Test User" <test@domain.com>MIME-Version: 1.0

Content-Type: text/plain; charset=UTF-8
Message-Id: <20100374043720.7BFBC2D7DB@mx.example.com>
Date: Tue, 18 May 2010 00:37:20 -0400 (EDT)</test@domain.com> 

And here are the header settings I am passing to mail():

'From: "Webmaster" <webmaster@example.com>\r\nReply-To: "Test User" <test@domain.com>\r\nMIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8'</test@domain.com></webmaster@example.com> 

Any ideas? Again, most of my user's see the message ok, so I am stumped. Anything I am obviously doing wrong here in the settings, or has anyone encountered this issue before?

Thanks!

3 Replies

Just in case anyone else is as silly as I am, the issue was with the spacing in the header itself… was using \r\n when I should have simply been using \n. Problem solved!

Avoid mail() if you can. It is difficult to secure, not to mention that it causes inconsistent behavior such as what you experienced.

SwiftMailer http://swiftmailer.org/ is much more powerful, and just as easy if not easier to use in your custom scripts. It is also dead easy to transition to something else (Google Apps or external SMTP servers) later on.

My mail needs are extrememly basic at this point, but will look into this SwiftMailer in the future.

Paul

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct