如何在PHP中使用段落发送消息 [英] How to send a message in php with paragraphs
问题描述
我正在使用下面的php代码发送消息
I'm using the php code below to send a message
<?php
$newline = $_GET['message'];
$newline = str_replace("[N]","\n","$newline");
$newline = str_replace("[n]","\n","$newline");
mail($_GET['to'],$_GET['subject'],$newline,"From: ".$_GET['from']);
header( 'Location: http://my_site.com/POMPC/report.html' ) ;
?>
不幸的是,当我发送邮件时,它出现了,但是所有内容都显示在了一条清晰的线中,使邮件混乱了.
sadly, when I send the message, it appears but everything appears in a straignt line, messing up the message.
示例:
Hello,
This is a message.
Reply.
显示为
您好,这是一条消息.回复.
Hello,This is a message. Reply.
一切都在严格的范围内,把东西弄乱了.如何维护格式.我发送的消息来自我的桌面应用程序,并且向我发送用户定义的数据.
Everything is in a straignt line and messes up stuff. How do I mantain the formatting. The message I'm sending is from my desktop application and sends user defined data to me.
推荐答案
如果您想要HTML段落:
仅使用mail()
函数,您就必须像这样编写HTML源代码:
If you want HTML paragraphs:
Using just the mail()
function you would have to compose the HTML source like this:
请勿在第3个参数$message
中写入任何内容,只需将其保留为空白''
.并像这样构成其余部分:
Do not write anything in the 3rd parameter $message
, just leave it blank ''
. And compose rest as such:
$additional_headers = <<<MAIL
Content-Type: multipart/alternative; boundary=00151747835895c6f804c48dc14b
--00151747835895c6f804c48dc14b
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Pararaph 1
Pararaph 2
--00151747835895c6f804c48dc14b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<p>Pararaph 1</p>
<p>Pararaph 2</p>
--00151747835895c6f804c48dc14b--
MAIL;
$additional_headers = str_replace("\n", "\r\n", $additional_headers);
确保纯文本/文本区域中的文本被一个或多个\r\n
分隔,以使视觉效果类似于html段落.
Make sure the text in the plain/text area is separated by one or more \r\n
to get a visual feel similar to the html paragraphs.
这篇关于如何在PHP中使用段落发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!