php 向文本/普通电子邮件添加换行符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9619001/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:17:06  来源:igfitidea点击:

Adding line breaks to a text/plain email

phpemailswiftmailerplaintext

提问by Chuck Le Butt

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

我在发送plain text(不是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; charset=utf-8

Does anyone have any experience with this?

有人对这个有经验么?

采纳答案by jprofitt

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

回答by silly

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