Adding line breaks to a text/plain email
Asked Answered
H

2

43

I'm having a problem sending a plain text (not HTML!) email, all my line breaks are being ignored:

->setBody('Did you request a password reset for your account?\r\n\r\nIf yes, click here:\r\nhttp://www.website.com', 'text/plain');

The above is being displayed in the email as:

Did you request a password reset for your account?\r\n\r\nIf yes, click here:\nhttp://www.website.com

I've checked and the header is apparently set correctly:

Content-Type: text/plain; charset=utf-8

Does anyone have any experience with this?

Hanukkah answered 8/3, 2012 at 14:15 Comment(1)
@John That is not the right answer in this situation.Hanukkah
A
45

You are using literal strings. If you would like to add the line breaks, use double quotes instead of a single quote.

->setBody("Did you request a password reset for your account?\r\n\r\nIf yes, click here:\r\nhttp://www.website.com", 'text/plain');
Aultman answered 8/3, 2012 at 14:23 Comment(1)
Although @Rhodia beat you by a few seconds, you do actually give a reason as to why it wasn't working. I should have marked yours correct to begin with.Hanukkah
R
62

use double quotes like this

->setBody("Did you request a password reset for your account?\r\n\r\nIf yes, click here:\r\nhttp://www.website.com", 'text/plain');
Rhodia answered 8/3, 2012 at 14:23 Comment(0)
A
45

You are using literal strings. If you would like to add the line breaks, use double quotes instead of a single quote.

->setBody("Did you request a password reset for your account?\r\n\r\nIf yes, click here:\r\nhttp://www.website.com", 'text/plain');
Aultman answered 8/3, 2012 at 14:23 Comment(1)
Although @Rhodia beat you by a few seconds, you do actually give a reason as to why it wasn't working. I should have marked yours correct to begin with.Hanukkah

© 2022 - 2024 — McMap. All rights reserved.