php电子邮件中的HTML标记

php电子邮件中的HTML标记,php,html,email,html-email,Php,Html,Email,Html Email,我想用php和一些HTML发送电子邮件。 在我的电子邮件中,它给了我 Hello <strong>,</strong><br><br> 消息变量: $message = "Hello <strong>,</strong><br><br> To verify your email and complete your registration please click on the li

我想用php和一些HTML发送电子邮件。 在我的电子邮件中,它给了我

Hello <strong>,</strong><br><br>
消息变量:

$message = "Hello <strong>,</strong><br><br>
        To verify your email and complete your registration please click on the link below: <br /><br />
        <a href='<?=$link?>'>VERIFY ACCOUNT</a>";
您需要在标题上设置内容类型:text/html

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
并将其添加到您的邮件中


为了更好地理解,请参考以下脚本:

 <?php
    $to = "somebody@example.com, somebodyelse@example.com";
    $subject = "HTML email";

    $message = "
    <html>
    <head>
    <title>HTML email</title>
    </head>
    <body>Hello <strong>,</strong><br><br>
    </body>
    </html>
    ";

    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= 'From: <webmaster@example.com>' . "\r\n";
    $headers .= 'Cc: myboss@example.com' . "\r\n";

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

我需要在邮件函数中传递头变量吗当然需要。你必须这么做。请参阅我提供的链接。它给你一个清晰的理解。特别是看示例4I,我能够传递html表单。但是,问题是它现在没有传递php变量..你能发布你的问题的尝试,这样我们就可以看一看吗?哦。。很抱歉这是一个愚蠢的错误。如果你想发送除最简单的邮件以外的任何东西,你最好选择一个库,比如Swift Mailer或PHP Mailer。起初这看起来很简单,但一旦你进入了由多部分邮件、附件等组成的世界,你就会发现自己编写了很多其实不需要的代码,然后发现你的很多邮件都被垃圾邮件文件夹捕获了。
mail($to, $subject, $message, $headers); //<--- Like that.
$message = "Hello <strong>,</strong><br><br>
        To verify your email and complete your registration please click on the link below: <br /><br />
        <a href=$link>VERIFY ACCOUNT</a>";
 <?php
    $to = "somebody@example.com, somebodyelse@example.com";
    $subject = "HTML email";

    $message = "
    <html>
    <head>
    <title>HTML email</title>
    </head>
    <body>Hello <strong>,</strong><br><br>
    </body>
    </html>
    ";

    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= 'From: <webmaster@example.com>' . "\r\n";
    $headers .= 'Cc: myboss@example.com' . "\r\n";

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