试图在php变量中插入换行符

时间:2013-12-22 13:30:09

标签: php

请耐心等待我,因为我还是很陌生。我只是想确保下面的电子邮件正文包含我放置<br/>的换行符。但是,当我运行脚本时,消息体显示与脚本中的完全相同,即使它在编辑器中完美地工作,我曾经在Stackoverflow上编写此电子邮件。

我意识到它的东西非常小而微妙。 / n似乎也没有用。谢谢你的帮助!我不确定我是否理解如何在我的特定环境中使用nl2br。再次感谢您的耐心和帮助。

$subject=" You're exclusive guide is only a click away!"; 
$message="Thanks for subscribing .$name! <br/> Click below to confirm your email and email and access your guide <br/> http://acmecorp.net/guide <br/> Acmecorp.net <br />Phone: 800-123-4468";
$headers = 'From:AcmeCorp<info@acmecorp.net>';
mail( $email, $subject, $message,$headers );`

2 个答案:

答案 0 :(得分:0)

您希望明显在邮件中使用HTML标记。因此,您必须通过在标题中添加内容类型来发送HTML格式的邮件。

mail()来电之前,添加$headers .= "Content-type: text/html\r\n";以获得类似内容:

$subject = " You're exclusive guide is only a click away!"; 
$message = "Thanks for subscribing .$name! <br/> Click below to confirm your email and email and access your guide <br/> http://acmecorp.net/guide <br/> Acmecorp.net <br />Phone: 800-123-4468";
$headers = 'From:AcmeCorp<info@acmecorp.net>';
$headers .= "Content-type: text/html\r\n";
mail($email, $subject, $message, $headers);

答案 1 :(得分:0)

用“\ n”代替<br/>

$subject=" You're exclusive guide is only a click away!"; 
$message="Thanks for subscribing .$name! \n Click below to confirm your email and email and access your guide \n http://acmecorp.net/guide \n Acmecorp.net \nPhone: 800-123-4468";
$headers = 'From:AcmeCorp<info@acmecorp.net>';
mail( $email, $subject, $message,$headers );`