PHP邮件功能无法发送HTML

时间:2015-07-09 11:32:01

标签: php email

我正在尝试发送带有链接的电子邮件,我面临的问题是Outlook不会重新整理正在放入电子邮件中的HTML。

$onderwerp = "test";
$bericht = <<<EOT
<html>
<head>
  <title>Email_test</title>
</head>
<body>
 <a href="http://www.link.com/index.php?page=members&id={$last_insert_id}">* the link</a> 
</body>
</html>     
EOT;

$headers = 'From: ' . $verstuurd_van;

mail($naar_1, $onderwerp, $bericht, $headers);          

感谢正手帮助。

2 个答案:

答案 0 :(得分:2)

为了能够发送HTML电子邮件,您需要添加更多标题:

        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

所以整个电子邮件变成了:

$to = 'example@example.com';
        $subject = 'Test';
        $message = "
        <html>
            <body>
                <p>
                    Hallo <b>Example</b>,
                </p>

            </body>
        </html>";
        $headers = "From: example@example.nl\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

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

另请查看:https://css-tricks.com/sending-nice-html-email-with-php/

答案 1 :(得分:0)

只需提及电子邮件脚本中的标题,例如。

// 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";

所以你的脚本将

$onderwerp = "test";
$bericht = <<<EOT
<html>
<head>
  <title>Email_test</title>
</head>
<body>
 <a href="http://www.link.com/index.php?page=members&id={$last_insert_id}">* the link</a> 
</body>
</html>     
EOT;

$headers = 'From: ' . $verstuurd_van;
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($naar_1, $onderwerp, $bericht, $headers); 

您可以参考html email with phpw3school email html