Php 发送html电子邮件并以文本形式接收
我使用以下php代码发送HTML电子邮件:Php 发送html电子邮件并以文本形式接收,php,email,sendmail,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:
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);
}
函数sendmail($to、$from、$subject、$body){
$To=$To;
$Subject=$Subject;
$Message=$body;
$from=“不回复”;
$Headers=“From:sender@taskmanager.domain.ca“\r\n”。
答复:“.$from”。\r\n”。
“MIME版本:1.0”。“\r\n”。
'内容类型:text/html;charset=iso-8859-1'。“\r\n”;
邮件($To、$Subject、$Message、$Headers);
}
函数sendEmailUser($fromUserObj,$userInfo){
$html=”
亲爱的“$userInfo[“firstName”]。$userInfo[“lastName”]。”
欢迎光临
帐户信息:
用户名:“.$userInfo[“Username”]”
密码:“.$userInfo[“Password”]”
您可以登录
";
$subject=“subject”;
sendmail($userInfo[“email”],$subject,$html);
}
我收到的电子邮件是普通文本,没有html解释
<html> <body> <p> Dear test lastname ,</p> <p> Welcome to IT.</p> ... </html>
亲爱的test lastname,欢迎使用它。。。。
我的代码有什么问题??
请帮忙,我会很感激的 函数sendmail参数->($to、$from、$subject、$body)(4个参数) 您正在呼叫->发送电子邮件($userInfo[“email”],$subject,$html);(3个参数) 应该是:
sendEmail($userInfo[“email”],$email\u from,$subject,$html) 尝试像这样贴花标题变量
$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";
这也可能是电子邮件客户端的问题。看起来不错,检查收到的电子邮件的来源,可能是电子邮件客户端强制使用纯文本?我的电子邮件客户端是gmail,我认为它支持HTML邮件。服务器通过gmail帐户发送电子邮件,内容类型可能区分大小写。两个字母的开头都是大写对不起,这是一个非常愚蠢的错误。问题是,我将主体而不是主体作为错误参数发送。身体是空的。所以gmail显示的是主题而不是身体。