如何在PHP mail()中使文本变为粗体?

时间:2014-02-27 05:54:14

标签: php function email syntax output

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

$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);

我还使用了<strong>而不是<b>标记,但没有任何效果。 我收到以下格式的邮件:

<b>Namn:</b> some name

Adress:
Borås, Sweden
4837, Boras

E-post: somemail@gmail.com

2 个答案:

答案 0 :(得分:12)

您将再次覆盖标头变量。你需要附加它。

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

答案 1 :(得分:2)

尝试在span中设置字体权重属性:

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

但是也看到其他回复,你正在覆盖标题,所以它不是以HTML格式阅读消息。