【问题标题】:How to make a text bold in PHP mail()?如何在 PHP mail() 中使文本变为粗体?
【发布时间】:2014-03-30 09:20:39
【问题描述】:

我想在我的电子邮件内容中以粗体形式邮寄一些文本。我使用了以下代码

$to = 'some@gmail.com';
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
        $from = $param['email']; // this is the sender's Email address
    $headers = "From:" . $from;

    $name = $param['name'];

    $subject = "Test";

    $message =  "message.\n\n" 
                ."<b>Name:</b> ".$name . "\n\n"
                ."Adress: \n" 
                .$param['address'] . "\n"
                .$param['zip'] . ", "
                .$param['postal_area'] . "\n\n"
                ."E-post: ".$param['email'] . "\n\n\n"

      mail($to,$subject,$message,$headers);

我也使用&lt;strong&gt; 代替&lt;b&gt; 标签,但没有任何效果。 我收到以下格式的邮件:

<b>Namn:</b> some name

Adress:
Borås, Sweden
4837, Boras

E-post: somemail@gmail.com

【问题讨论】:

    标签: php function email syntax output


    【解决方案1】:

    您再次覆盖了标头变量。您需要附加到它。

     $headers .= "From:" . $from; //You forgot to concatenate here...
    //     ---^ //Add the .
    

    【讨论】:

      【解决方案2】:

      尝试在 span 中设置字体粗细属性:

      $message = "E-post: <span style='font-weight:strong;'>".$param['email']."</span>";
      

      但也请参阅其他回复,您正在覆盖标题,因此它不会以 HTML 格式读取消息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多