PHP邮件html格式不工作 [英] PHP mail html format not working

查看:126
本文介绍了PHP邮件html格式不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用php,并使用这段代码,我收到的电子邮件是一个纯文本,我错过了什么吗?因为我需要发送可能包含链接的格式化电子邮件,例如。

Using php, and with this code I receive the email as a plain text, did I miss something? as I need to send formatted email which could contain links for example.

$to = "receiver@test.com";
$subject = "Password Recovery";

$body = '
<html>
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <title>Birthday Reminders for August</title>
    </head>
    <body>
        <p>Here are the birthdays upcoming in August!</p>
        <table>
            <tr>
                <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
            </tr>
            <tr>
                <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
            </tr>
            <tr>
                <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
            </tr>
        </table>
    </body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info@test.net\r\n"."X-Mailer: php";
if (mail($to, $subject, $body, $headers)) 
echo "Password recovery instructions been sent to your email<br>";


推荐答案

看这个例子,这足以发送邮件在php:

Look at this example, this is sufficient to send mail in php:

<?php 
    //change this to your email. 
    $to = "abc@gmail.com";
    $from = "Example@example.com";
    $subject = "Hello! This is HTML email";

    //begin of HTML message 
    $message ="
<html> 
  <body> 
    <p style=\"text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;\">
        <b>I am receiving HTML email</b>
        <br/><br/><br/><a style=\"text-decoration:none;color:#246;\" href=\"www.example.com\">example</a>
    </p>
    <br/><br/>Now you Can send HTML Email
  </body>
</html>";
   //end of message 
    $headers  = "From: $from\r\n"; 
    $headers .= "Content-type: text/html\r\n";

    //options to send to cc+bcc 
    //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]"; 
    //$headers .= "Bcc: [email]email@maaking.cXom[/email]"; 

    // now lets send the email. 
    mail($to, $subject, $message, $headers); 

    echo "Message has been sent....!"; 
?>

这篇关于PHP邮件html格式不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆