首页 > 解决方案 > 从 php echo 语法输出 html?

问题描述

我有一个 php 邮件脚本,它在表单上方的 div 上输出一条消息:

// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
}

我想为回显添加样式和换行符,但目前这是使用标签而不是代码输出它:

echo "<span>Thank You!</span><br />Your message has been sent.";

我也尝试将双引号更改为单引号,但没有奏效。

======================

** 编辑已解决 **

它没有显示 html 的原因是因为数据被发送到具有以下内容的 js 应用程序:

// Set the message text.
if (data.responseText !== '') {
    $(formMessages).text(data.responseText);
}

我用 .html 替换了 .text ,如下所示:

// Set the message text.
if (data.responseText !== '') {
    $(formMessages).html(data.responseText);
}

谢谢大家的建议。

标签: phphtmlsyntaxecho

解决方案


在关联的 js 文件上将 .text 更改为 .html。请参阅关于 OP 问题的解决方案。


推荐阅读