php - PHP 表单内的特定字体系列

标签 php css forms fonts font-family

我正在使用我在 HTML 中创建的表单在 PHP 中创建查询表单。是否可以像在 HTML 中那样在 PHP 代码中使用特定字体?例如:

    <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">

font-family: 'Quicksand', sans-serif;

下面您可以看到我所指的 PHP 代码:

$email_to = "billy.farroll@hotmail.com";
$name = $_POST["name"];
$email = $_POST["email"];
$tel = $_POST["tel"];
$msg = $_POST["msg"];

$email_from = "billy@slickfin.com"; // This email address has to be the same email on the server if using Fasthots server i.e. SlickFin server - billy@SlickFin.com you can't put the $email variable entered by user because its not authorised to send it.
$message = $_POST["message"];
$email_subject = "Enquiry";

例如,这部分(下面)我想使用 font-family: 'Quicksand', sans-serif; 作为我在填写并提交表单后收到的电子邮件。这是我的问题。

$headers =   
"From: $email .\n";   
"Reply-To: $email .\n"; // 
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";  
$message = '<html><body>';
$message .= "<h1 style='color: #0d1237;'>Enquiry</h1>";
$message .= "<h2 style='color: #0d1237; font-size: 22px;'> Name: " . $name . "</h1>";
$message .= "<p style='font-weight: bold;'> Email Address: " . $email . "</p>";
$message .= "<p style='font-weight: bold;'> Telephone Number: " . $tel . "</p>"; 
$message .= "<p style='font-weight: bold;'> Message: " . $msg ."</p>";
$message .= "</body></html>";

此外,这是我的 HTML 表单代码:

<section id="contact">
    <form action="enquiry.php" method="post">
          <div class="field name-box">
                <input type="text" name="name" id="name" placeholder="Who Are You?" tabindex="1" required>
                <label for="name">Name</label>
                <span>Done</span>
          </div>

          <div class="field email-box">
                <input type="text" name="email" id="email" placeholder="name@email.com" tabindex="2" required>
                <label for="email">Email</label>
                <span>Done</span>
          </div>

      <div class="field tel-box">
                <input type="text" name="tel" id="tel" placeholder="Telephone Number" tabindex="3" required>
                <label for="tel">Mobile</label>
                <span>Done</span>
          </div>

          <div class="field msg-box">
                <textarea id="msg" name="msg" rows="4" placeholder="What's Up?" tabindex="1" required></textarea>
                <label for="msg">Message</label>
                <span>Done</span>
          </div>

          <input class="button" name="submit" type="submit" value="Send" />
  </form>

如果您想查看整个 index.html 和整个 equiry.php 文件,您可以通过 Github 访问:https://github.com/billyfarroll/enquiry_slick_one

最佳答案

PHP 不是一种输出格式。 PHP 可能会操纵输出,但它不是输出本身。将 PHP 想象成一个计算器,将 HTML 想象成计算器屏幕上的数字。你的问题真的没有意义。

有许多不同的输出格式。 HTML只是其中之一,可能是除 JSON 之外您将主要使用的工具.

在这种情况下,您发送的似乎是 HTML 电子邮件。大多数电子邮件客户端将显示 HTML 和 CSS;类似于网络浏览器。您要做的是使用 PHP 来生成 一些CSS(一种输出格式)和HTML(也是一种输出格式)以获得您想要的结果。

HTML 电子邮件中的 CSS 比您在浏览器中可以执行的操作更受限制。为确保兼容性在此特定情况下,我建议使用 inline styles以获得您想要的效果。

要在您的 HTML 电子邮件中添加您不希望客户拥有的字体,您也可以这样做...

<html>
  <head>
    <style>
    @font-face {
      font-family: 'Lato';
      font-style: normal;
      font-weight: 400;
      src: local('Lato Regular'), local('Lato-Regular'), url(https://some-site/email.woff) format('woff');
    }
    body {
      font-family: "Lato", "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
    }
    </style>
  </head>
</html>

请注意,这将适用于某些电子邮件客户端,而不适用于其他客户端...因此请确保在您的 CSS 中使用一些后备字体。

关于php - PHP 表单内的特定字体系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50536801/

相关文章:

python - 根据 ModelChoiceField 获取 ModelMultipleChoiceField 字段的查询集

javascript - 如何使用jquery从输入字段模态 Bootstrap 获取值并将值显示到同一模态中的另一个输入字段?

javascript - css 样式单选按钮干扰 jquery 验证

javascript - 如何使用 html 表单数据发送 JSON 对象

javascript - 如果未选择,则删除强制选项

html - 列表全尺寸边框

php - Laravel 中的日期为 0000-00-00

php - 在 WooCommerce 电子邮件 Hook 中运行的参数太少

PHP 和 MySQL : 72 hours expiration for a task

javascript - 用 jquery 交换不连续的元素?