You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PHP生成的HTML格式询盘邮件中指定Quicksand字体?

How to Use Quicksand Font in PHP-Sent HTML Emails

Hey there! To get the Quicksand font working in your HTML emails, you need to account for how email clients handle web fonts—they’re a bit pickier than standard browsers. Here’s how to adjust your PHP code and email markup properly:

Step 1: Add the Web Font Reference to Your Email's HTML Head

First, you’ll need to include the Quicksand font reference inside a <head> section in your email HTML. Most modern email clients support Google Fonts via <link> or @import, though support varies (we’ll cover fallbacks next).

Step 2: Update Inline Styles & Add Font Fallbacks

Email clients prioritize inline styles, so you’ll want to set font-family: 'Quicksand', sans-serif; on all text elements. The sans-serif fallback ensures your email still looks clean if the web font doesn’t load (critical for clients like Outlook Desktop).

Also, fix the syntax error in your original code: you closed an <h2> tag with </h1>—that’ll break rendering in some clients.

Step 3: Fix Your PHP Header Syntax

Your original $headers variable had incorrect string concatenation. Let’s clean that up to ensure the email sends with proper MIME settings.

Modified PHP Code

// Fix header syntax
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

// Build the email message with Quicksand font
$message = '<html>
<head>
    <link href="https://fonts.googleapis.com/css?family=Quicksand" rel="stylesheet">
    <style>
        /* Optional: Embedded style for broader client support */
        body, h1, h2, p {
            font-family: \'Quicksand\', sans-serif;
        }
    </style>
</head>
<body>';
$message .= "<h1 style='color: #0d1237; font-family: \"Quicksand\", sans-serif;'>Enquiry</h1>";
$message .= "<h2 style='color: #0d1237; font-size: 22px; font-family: \"Quicksand\", sans-serif;'> Name: " . $name . "</h2>"; // Fixed closing tag
$message .= "<p style='font-weight: bold; font-family: \"Quicksand\", sans-serif;'> Email Address: " . $email . "</p>";
$message .= "<p style='font-weight: bold; font-family: \"Quicksand\", sans-serif;'> Telephone Number: " . $tel . "</p>";
$message .= "<p style='font-weight: bold; font-family: \"Quicksand\", sans-serif;'> Message: " . $msg ."</p>";
$message .= "</body></html>";

Key Notes on Email Font Compatibility

  • Supported Clients: Gmail, Apple Mail, iOS Mail, and most web-based clients will load Quicksand correctly.
  • Unsupported Clients: Outlook Desktop (Windows) and some older mobile clients will fall back to sans-serif, which is intentional and avoids broken rendering.
  • Embedded + Inline Styles: Using both embedded CSS (in the <head>) and inline styles gives the best chance of the font loading across clients.

内容的提问来源于stack exchange,提问作者billy.farroll

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:55:22