views:

105

answers:

2

I'm using PHP _EOL when building the message body of my email but the line feeds are not getting through and the entire message body ends up one long line in the resultant email. This happens regardless of Multi-part or html only messages. Sending as text only it works fine, but of course I want to send Multi-part messages.... Any ideas?

A: 

I've never even used PHP_EOL before, but I wonder if it is set to the type of your server, not of the recipient. I don't see how a constant could be correct for all recipients, that doesn't make sense.

Usually '\n' is all that is needed... in some cases you may need '\r\n' depending on the protocol involved. What are you using to send the email? What are you using to view the email?

DGM
PHP _EOL is a constant that adjusts for each server type. But since I'm using a Windows server, sending to a Windows client, through the gmail mail server, I would expect the html-email to properly display the line feeds.
SMTP requires CRLF... see http://www.ietf.org/rfc/rfc2821.txt section 2.3.7
DGM
+1  A: 

Uhm. If there are no line breaks in your HTML email, it's probably because neither a \n nor a \r\n is a newline in HTML; a <br /> tag is.

chaos
I thought email accepted \r\n even in HTML only mode. I'm guessing I'm incorrect and my html emails must be 100% html to format as expected?
Yeah. I mean, it *accepts* the \r\n, as far as that goes, it just renders it as normal for HTML: as generic whitespace.
chaos
Yeah, that's the problem I'm having, so I need to have two different mail messages formatted for text only and HTML if I want to send mail out Multi-part
Well... if you're not doing HTML formatting in it, what's the point of sending out an HTML part? If it's just mimicking plaintext, send plaintext. If for some reason you really need an HTML rendition of a plaintext message, though, it doesn't seem so bad to put a <br> before each newline.
chaos
I guess I need the HTML more than the plain text. It will have coded links to sections of the site and plain text just doesn't work very well like that.
Ah, I see. Yeah, in that case you'll need to at least put <br>s for your newlines, more preferably do proper formatting with <p>s and whatnot.
chaos
And forget Multi-part, just output HTML only.
Gonna anger people who don't want to look at HTML email then.
chaos
See, so I'm back to multi-part and two sets of formatted text.... not terribly difficult, but I was hoping for a break! And those hard core text guys will have to cut and paste the links I provide...