PHP nl2br()基本功能 [英] PHP nl2br() basic function

查看:41
本文介绍了PHP nl2br()基本功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我这个邮件脚本吗?

Can somebody please help me with this mail script.

我只是想发送html电子邮件,而消息的一部分来自用户文本区域,该文本区域放置在\ r \ n中.

I'm simply trying to send an html email and part of the message is from a user textarea, which puts in \r\n.

我似乎无法使用nl2br或任何其他类似的功能.下面的代码不是我正在使用的代码,但仍然会产生错误.

I seem to be unable to use nl2br or any other similar function. The code below isn't what I'm using but still produces the error.

代码:

$to  = 'example@gmail.com';

$subject = 'Test Subject';

$message_var_1 = 'test1 \r\n test2 \r\n test3';
$message = nl2br("
    <div>
    <div>$message_var_1</div>
    </div>
");

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/'.phpversion() . "\r\n";

mail($to, $subject, $message, $headers);

推荐答案

$message_var_1 = 'test1 \r\n test2 \r\n test3';

PHP仅在"内而不是'内解析\r\n.因此nl2br不适用于此处.

PHP parses \r and \n only within ", not within '. So nl2br won't apply here.

$message_var_1 = "test1 \r\n test2 \r\n test3";
$message = '<div>
     <div>'.nl2br($message_var_1).'</div>
</div>';

这应该起作用.

这篇关于PHP nl2br()基本功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆