\r\n 使用 PhpMailer 库发送电子邮件时替换不工作

发布于 2024-09-03 01:46:06 字数 391 浏览 4 评论 0原文

我一直在尝试使用 PHP 邮件库发送电子邮件,并取得了部分成功。
我面临的唯一问题是,当收件人收到邮件时,每个新行都显示为 \r\n 。

我已经尝试过这个:

$body = str_replace("\\r\\n", '\n', $body);
but it shows a '\n' instead of a new line.

I have also tried this:
$body = str_replace("\\r\\n", "\\n", $body);
but it shows nothing but a blank space. No new lines still :(

Can someone help me on this?

I have been trying to send emails, using the PHP Mail Library and have been partially successful.
The only problem that I am facing is, when the Mail is received by the receiver, every new line is shown as \r\n .


I have tried this:

$body = str_replace("\\r\\n", '\n', $body);

but it shows a '\n' instead of a new line.

I have also tried this:

$body = str_replace("\\r\\n", "\\n", $body);

but it shows nothing but a blank space. No new lines still :(

Can someone help me on this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

金橙橙 2024-09-10 01:46:06

它需要是:

$body = str_replace("\r\n", "\n", $body);

你的第一个例子几乎是正确的,除了你在单引号而不是双引号内有 \n 。

It needs to be:

$body = str_replace("\r\n", "\n", $body);

Your first example was almost right, apart from that you had \n inside single quotes instead of double quotes.

神妖 2024-09-10 01:46:06

试试这个

Blockquote$body = stripcslashes(isset($body) ? preg_replace(' (\\r|\\r\\n|\\n)#', '
', $body) : false);
$body = str_replace("

","
",$body);

这对我有用

Try this

Blockquote$body = stripcslashes(isset($body) ? preg_replace(' (\\r|\\r\\n|\\n)#', '
', $body) : false);
$body = str_replace("

","
",$body);

It works for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文