PHP 中表单内的特定字体系列

Specific font family inside a form in PHP

我正在 PHP 中创建查询表单,使用的是我在 HTML 中创建的表单。是否可以像在 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 is just one of them and is probably what you'll be working with mostly other than JSON.

在这种情况下,您发送的似乎是 HTML 电子邮件。大多数电子邮件客户端将显示 HTML 和 CSS;类似于网络浏览器。你要做的是 use PHP generate some 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 中使用一些后备字体。