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

Chu*_*utt 34 php email plaintext swiftmailer

发送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');
Run Code Online (Sandbox Code Playgroud)

以上内容将在电子邮件中显示为:

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

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

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

有人对这个有经验么?

sil*_*lly 55

使用这样的双引号

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


jpr*_*itt 30

您正在使用文字字符串.如果您想添加换行符,请使用双引号而不是单引号.

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