发送HTML电子邮件并以文本形式接收

时间:2013-06-06 11:12:20

标签: php email sendmail

我有这个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> 

我的代码出了什么问题? 请任何帮助我会很感激。

2 个答案:

答案 0 :(得分:0)

函数sendEmail参数 - &gt; ($ to,$ from,$ subject,$ body)(4个参数)

你正在打电话 - &gt; sendEmail($ userInfo [“email”],$ subject,$ html); (3个参数)

它应该是:

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

答案 1 :(得分:0)

尝试像这样声明你的标题变量

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