这个问题在这里已有答案:
我的php邮件脚本正在发送邮件,但即使 Headers 告诉它是html,它也会忽略它并将邮件作为文本发送 . 所有'\ r \ n'中断最终被忽略,$ header内容粘贴在电子邮件中的$ body下方 . 下面是代码 .
//mail out copy
$to = $email;
$subject = 'Thank you for signing up to Learn to Play';
$headers = 'From: donotreply@xxx.com' . '\r\n';
Always set content-type when sending HTML email
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$body = 'Thank you for registering with us for your Learn to Play Table Games Lesson. Your registration has been confirmed for ';
$body .= $date_requested;
$body .= ' for a group of ';
$body .= $guests;
$body .= '. Please check in at the Guest Services Desk at 6:45PM where a member of our Table Games Team will meet you for your session. ';
$body .= 'Should there be any conflict with your reservation a member of our team will contact you to re-schedule your lesson.';
mail($to, $subject, $headers, $body) or die('Error sending mail');
}
2 回答
你按错误的顺序做到了:
mail($to, $subject, $body, $headers) or die('Error sending mail');
您还必须使用双引号
"\r\n"
instate of single quotes'\r\n'
.示例
用于文本邮件:
对于HTML邮件:
http://php.net/manual/en/function.mail.php
这里:
改为:
因为
$headers
应该是最后一个参数 .