【问题标题】:send html email and receive it as text发送 html 电子邮件并以文本形式接收
【发布时间】:2013-06-02 09:00:26
【问题描述】:

我有这个 php 代码来发送 HTML 电子邮件:

 function sendEmail($to,$from,$subject,$body) {

    $To = $to;
    $Subject = $subject;
    $Message = $body;
    $from = "Do Not Reply";
    $Headers = "From: sender@taskmanager.domain.ca"." \r\n" . 
                "Reply-To: ".$from." \r\n" . 
                'MIME-Version: 1.0' . "\r\n".
                'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    mail($To, $Subject, $Message, $Headers);
}

function sendEmailUser($fromUserObj, $userInfo){
    $html="
    <html>
    <body>
        <p>
            Dear ".$userInfo["firstName"] ." ".$userInfo["lastName"]." ,</p>
        <p>
            Welcome to IT .</p>
        <p>
            Account Information:</p>
        <p>
            Username:".$userInfo["username"]."</p>
        <p>
            Password: ".$userInfo["password"]."</p>
        <p>
            You can login <a href = 'http://domain.com'>here</a> .</p></body>
        </html>";


    $subject = "subject";

    sendEmail($userInfo["email"], $subject, $html);
}

我收到电子邮件的普通文本,没有解释 html。

<html> <body> <p> Dear test lastname ,</p> <p> Welcome to IT.</p> ... </html> 

我的代码有什么问题?? 请任何帮助,我将不胜感激。

【问题讨论】:

  • 这也可能是电子邮件客户端问题。
  • 好像没问题,检查收到邮件的来源,可能是邮件客户端强制明文?
  • 我的电子邮件客户端是gmail,我认为它支持HTML 邮件。服务器也通过 gmail 帐户发送电子邮件
  • Content-Type 可能区分大小写。两个字母都以大写开头
  • 对不起,这是一个非常愚蠢的错误。我发送主题而不是正文作为错误参数的问题。身体是空的。所以gmail显示主题而不是正文。

标签: php email sendmail


【解决方案1】:

尝试像这样贴标头变量

$Headers = "From: sender@taskmanager.domain.ca"." \r\n";
$Headers .="Reply-To: ".$from." \r\n" ;
$Headers .= 'MIME-Version: 1.0' . "\r\n";
$Headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

【讨论】:

    【解决方案2】:

    函数sendEmail参数 -> ($to,$from,$subject,$body) (4个参数)

    你正在打电话 -> sendEmail($userInfo["email"], $subject, $html); (3个参数)

    应该是:

    sendEmail($userInfo["email"], $email_from, $subject, $html);

    【讨论】:

      猜你喜欢
      • 2021-04-12
      • 1970-01-01
      • 2019-04-20
      • 1970-01-01
      • 2012-04-29
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 2015-09-19
      相关资源
      最近更新 更多