简体   繁体   中英

Php mail function unable to send HTML

I am trying to send an email with a link, the problem im facing is that outlook does not reconize the HTML which is being put in the email.

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

Thanks in forehand for the help.

In order to be able to send a HTML email you need to add a few more headers:

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

So the entire email becomes something like:

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

Also take a look at: https://css-tricks.com/sending-nice-html-email-with-php/

just mention the headers in your email script like .

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

so your script will

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

you can take reference from html email with php or w3school email html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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