Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP邮件换行符_Php_Email_Line Breaks - Fatal编程技术网

PHP邮件换行符

PHP邮件换行符,php,email,line-breaks,Php,Email,Line Breaks,我有一个php邮件脚本,只要我在变量中定义正文文本,它就可以正常工作,如下所示: $body = "Some text goes here\n\nSome other text goes here!"; define('_body_', 'Some text goes here\n\nSome other text goes here!'); $body = _body_; 这样做时,换行符“\n”在邮件中的效果非常好 现在,我想在一个配置文件中插入正文文本,邮件脚本从中检索文本。因此,我

我有一个php邮件脚本,只要我在变量中定义正文文本,它就可以正常工作,如下所示:

$body = "Some text goes here\n\nSome other text goes here!";
define('_body_', 'Some text goes here\n\nSome other text goes here!');
$body = _body_;
这样做时,换行符“\n”在邮件中的效果非常好

现在,我想在一个配置文件中插入正文文本,邮件脚本从中检索文本。因此,我在配置文件中设置一个常量,如下所示:

$body = "Some text goes here\n\nSome other text goes here!";
define('_body_', 'Some text goes here\n\nSome other text goes here!');
$body = _body_;
我的邮件脚本现在如下所示:

$body = "Some text goes here\n\nSome other text goes here!";
define('_body_', 'Some text goes here\n\nSome other text goes here!');
$body = _body_;
但是现在换行符没有在邮件中“显示”。相反,邮件如下所示:

$body = "Some text goes here\n\nSome other text goes here!";
define('_body_', 'Some text goes here\n\nSome other text goes here!');
$body = _body_;
“有些文字在这里\n\n有些文字在这里!”


关于如何解决这个问题有什么想法吗?

这是因为您使用的是单引号

试一试


\n
如果在双引号内(如第一个示例所示),但不在单引号内(如第二个示例所示),则将转换为换行符。

使用双引号定义:

define('_body_', "Some text goes here\n\nSome other text goes here!");

使用双引号(
)而不是单引号(
)我很惊讶人们会因为没有经验的人知道的不多而否决一个帖子。真的很了不起。我们都是从某个地方开始的。谢谢nickhar。对一些人来说,众所周知且相对简单的事情同时也是其他人的新领域。这不正是Stackoverflow和其他人喜欢它的原因吗?汉弗莱:谢谢!感觉有点愚蠢:)不用担心,一开始容易犯错误!