【发布时间】:2015-03-17 16:47:45
【问题描述】:
我有一个包含多个部分的电子邮件脚本,它接受一个已发布的电子邮件地址,并以 HTML 和/或纯文本格式向他们发送一封简单的电子邮件。它在 Gmail 和 Outlook 中正确显示,但在 eM 中显示不正确(甚至无法连接到 Communigate 服务器)。代码:
<?php
$email_address = addslashes($_POST['email_address']);
if (!filter_var($email_address, FILTER_VALIDATE_EMAIL)) {
header("Location: ./?error=invalid-email");
exit();
}
$subject_line = "This is a test multi-part email";
$boundary = uniqid();
$headers = "MIME-Version:1.0\r\n";
$headers .= "From: Maggie Multipart <web@ukipme.com>\r\n";
$headers .= "To: " . $email_address . "\r\n";
$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n";
$message = "This is a MIME encoded message.";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/plain;charset=utf-8\r\n\r\n";
$message .= "Hello,\nThis is a test email, the text/plain version.\n\nRegards\nMaggie Multipart";
$message .= "\r\n\r\n--" . $boundary . "\r\n";
$message .= "Content-Type: text/html;charset=utf-8\r\n\r\n";
$message .= "<p>Hello,<br>This is a test email, the text/html version.</p><p>Regards<br><strong>Maggie Multipart</strong></p>";
$message .= "\r\n\r\n--" . $boundary . "--";
mail("", $subject_line, $message, $headers);
header("Location: ./?success=email-sent");
exit();
// var_dump($_POST);
?>
eM中收到的消息如下:
内容类型:text/plain;charset=utf-8
你好,
这是一封测试邮件,文本/纯文本版本。
问候
玛吉多部分
但是,eM 设置为接收 HTML 电子邮件(并且经常这样做)。有人可以帮我解决这个问题吗?我是否缺少任何标题?
【问题讨论】: