php - 从 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);
}
谢谢大家的建议。
解决方案
在关联的 js 文件上将 .text 更改为 .html。请参阅关于 OP 问题的解决方案。
推荐阅读
- css - 如何根据我在 React Native 中的屏幕大小更改 svg 大小?
- amazon-web-services - 如何知道哪个 AWS RDS 数据库正在使用特定密钥?
- ruby - ruby mixin 可以访问它所混入的类中存在的变量吗?
- karate - 空手道-如何仅在失败的情况下自动重新运行
- spring-boot - 如何指定服务器发送 Socket 消息?
- python - Python CSV 保存
- java - TreeContentProvider 只是获取我路径的每个目录。(文件过滤器)
- python - Python:使用正则表达式定义边界
- javascript - 试图添加。8 到以前的总和
- python - 如何在 Python 中移动 DataFrame 列的数字或字符串中的位置点?