简体   繁体   English

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

[英]How to make a text bold in PHP mail()?

I would like to mail some text as bold in my email content. 我想在我的电子邮件内容中将一些文本邮寄为粗体。 I have used the following code 我使用了以下代码

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

I have used <strong> also instead of <b> tag, but nothing works. 我使用<strong>而不是<b>标签,但没有任何作用。 I get mail in the below format : 我收到以下格式的邮件:

<b>Namn:</b> some name

Adress:
Borås, Sweden
4837, Boras

E-post: somemail@gmail.com

You are overwriting the header variable again. 您将再次覆盖标头变量。 You need to append to it. 你需要附加它。

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

Try setting the font weight property in a span: 尝试在span中设置字体权重属性:

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

But also see other reply, you are overwriting the header so it is not reading the message as HTML. 但也看到其他回复,你正在覆盖标题,所以它不是以HTML格式阅读邮件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM