在文本/纯文本电子邮件中添加换行符

时间:2022-03-14 18:17:39

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

我在发送纯文本(不是HTML!)电子邮件时遇到问题,我的所有换行符都被忽略了:

->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

您是否要求为您的帐户重置密码?\ r \ n \ r \ n如果是,请点击此处:\ nhttp://www.website.com

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

我已经检查过,标题显然设置正确:

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

Content-Type:text / plain;字符集= utf-8的

Does anyone have any experience with this?

有人对这个有经验么?

2 个解决方案

#1


18  

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');

#2


54  

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');

#1


18  

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');

#2


54  

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');