首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PHP邮件html格式不起作用

PHP邮件html格式不起作用
EN

Stack Overflow用户
提问于 2012-08-17 03:57:31
回答 4查看 33.1K关注 0票数 9

使用php,通过这段代码,我收到了纯文本形式的电子邮件,我是不是遗漏了什么?因为我需要发送格式化的电子邮件,其中可能包含链接,例如。

代码语言:javascript
复制
$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>";
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-08-17 04:00:10

看看这个例子,用php发送邮件就足够了:

代码语言:javascript
复制
<?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....!"; 
?>
票数 16
EN

Stack Overflow用户

发布于 2012-08-17 03:59:59

您已重新设置了标头:

代码语言:javascript
复制
$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";

您在最后一行中遗漏了一个点,这将覆盖前两行:

代码语言:javascript
复制
$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";
票数 22
EN

Stack Overflow用户

发布于 2015-06-11 13:45:16

我在一个特定的邮件服务器上发现了同样的问题,在我的例子中,解决方案是将"\n“而不是"\r\n”设置为标题的行尾。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11994556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档