我正在尝试发送几封电子邮件,当然我需要中断一些行并放置一些空格。这就是我试图做到的方式,没有运气:
for ($i = 0; $i < count($dataArray); $i++) {
$to = $dataArray[$i]['email'];
$subject = 'New member message';
$message = "Hello!" . "'r'n" . "Member message: " . "'r'n" . "'r'n" . $dataArray[$i]['message'] . "'r'n" . "'r'n" . "This is an automated message, please do not respond to it!";
$headers = 'From: info@domain.com' . "'r'n" .
'Reply-To: info@domain.com' . "'r'n" .
'Content-Type: text/html; charset=UTF-8' . "'r'n" .
'MIME-Version: 1.0' . "'r'n" .
'Content-Transfer-Encoding: quoted-printable' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
但是结果会导致单行文本,包括其中的'r'n
作为文本 - 它没有插入新行。
如何插入新行?为什么'r'n
不起作用?
我知道我在这里错过了一个非常非常小的部分,但作为一个 php 初学者,我无法发现它。
对于Content-type: text/html
,换行<br>
对于Content-type: text/plain
,新行'r'n
Try <br> tag before /r/n. hope it will work.
你必须使用一个简单的 <br />
对于新行, 'r'n
仅用于标题
试试这段代码。
for ($i = 0; $i < count($dataArray); $i++) {
$to = $dataArray[$i]['email'];
$subject = 'Testing sendmail.exe';
$message = "Hello!" . "'r'n" . "Member message: " . "'r'n" . "'r'n" . $dataArray[$i]['message'] . "'r'n" . "'r'n" . "This is an automated message, please do not respond to it!";
$headers = 'From: info@domain.com' . "'r'n" .
'Reply-To: info@domain.com' . "'r'n" .
'MIME-Version: 1.0' . "'r'n" .
'Content-type: text/html; charset=iso-8859-1' . "'r'n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
{
echo 'mail send';
}
else
{
echo 'mail fail';
}
}
将标头的内容类型更改为"内容类型:文本/html;字符集=iso-8859-1"