2

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

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

4

2 回答 2

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";
于 2013-06-15T11:55:07.667 回答
0

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

您正在调用 -> sendEmail($userInfo["email"], $subject, $html); (3个参数)

它应该是:

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

于 2013-06-14T17:38:00.467 回答