2
私はHTMLメールを送信するためにPHPMailerを使用しています。電子メールは正常に送信されますが、HTMLは電子メールクライアントに表示されません。私はこれをウェブベースのGMailとOSXのmail.appでテストしました。同じGmailアカウントにIMAPされています。どちらも正しく表示されません。PHPMailer HTMLがレンダリングされない
私はこれを解決するために私の髪を引っ張っています。何か案は???
PHPコード送信する電子メールをフォーマットする(電子メールをするよう送信されますが働いている):
// mail format settings
// $mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->CharSet="UTF-8"; // set the charset to UTF-8
$mail->Encoding = '7bit';
$body = '';
$body .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
$body .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
$body .= "<head>";
$body .= "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />";
$body .= "<meta http-equiv=\"Content-Language\" content=\"en-us\" />";
$body .= "<style>";
$body .= "body {font-family:\"trebuchet ms\", arial, \"san serif\";font-size:14px;}";
$body .= ".email-header{ margin:5px;padding:20px;background:#dddddd;border-radius:10px;color:#000000;font-size:24px;font-weight:bold;}";
$body .= ".email-body{margin:10px 20px;}";
$body .= "</style>";
$body .= "</head>";
$body .= "<body>";
if ($_POST["type"]=='confirmation') {
// set the email body
$body .= "<div class=\"email-header\">Sky Lodge HOA Reservation Confirmation</div>";
$body .= "<div class=\"email-body\">";
$body .= "Dear ". $_POST["name"] . ",<br/><br/>";
$body .= "This email is confirming your reservation for unit nnn x:<br/>";
$body .= "<strong>Arriving:</strong> date<br/>";
$body .= "<strong>Departing:</strong> date<br/><br/>";
$body .= "Please click here to view your existing reservation(s):<br/>";
$body .= "http://www.somesite.com/index.php?token=" . $_POST["token"] . "<br/><br/>";
// set the email subject
$mail->Subject = "Sky Lodge HOA: Reservation Confirmation";
} else if ($_POST["type"]=='notify') {
// set the email body
$body .= "<div class=\"email-header\">Sky Lodge HOA Attention Required</div>";
$body .= "<div class\"email-body\">";
$body .= "Dear ". $_POST["name"] . ",<br/><br/>";
$body .= "It is your turn to make a reservation for unit nnn x.<br/><br/>";
$body .= "Please click here to make your reservation:<br/>";
$body .= "http://www.somesite.com/index.php?token=" . $_POST["token"] . "<br/><br/>";
// set the email subject
$mail->Subject = "Sky Lodge HOA: Attention Required";
}
$body .= "Thank You,<br/>Patti Rea";
$body .= "</div>";
$body .= "</body>";
$body .= "</html>";
echo('$body: ' . $body);
$mail->Body = $body;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
結果のメール:
Return-Path: <[email protected]>
Received: from skylodge (c-174-52-123-157.hsd1.ut.comcast.net. [174.52.123.157])
by mx.google.com with ESMTPS id ko12sm7817099pbb.52.2012.02.29.11.02.07
(version=SSLv3 cipher=OTHER);
Wed, 29 Feb 2012 11:02:07 -0800 (PST)
Date: Wed, 29 Feb 2012 12:02:05 -0700
Return-Path: [email protected]
To: Sky Lodge <[email protected]>
From: Darren Ehlers <[email protected]>
Cc: [email protected]
Reply-To: Darren Ehlers <[email protected]>
Subject: Sky Lodge HOA: Reservation Confirmation
Message-ID: <[email protected]>
X-Priority: 3
X-Mailer: PHPMailer 5.2.1 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="b1_9941ff8576a1763200e134b5b313b1b1"
--b1_9941ff8576a1763200e134b5b313b1b1
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
This is the body in plain text for non-HTML mail clients
--b1_9941ff8576a1763200e134b5b313b1b1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Language" content="en-us" />
<style>
body {font-family:"trebuchet ms", arial, "san serif";font-size:14px;}
.email-header{ margin:5px;padding:20px;background:#dddddd;border-radius:10px;color:#000000;font-size:24px;font-weight:bold;}
.email-body{margin:10px 20px;}</style>
</head>
<body>
<div class="email-header">Sky Lodge HOA Reservation Confirmation</div>
<div class="email-body">
Dear Sky Lodge,<br/><br/>
This email is confirming your reservation for unit nnn x:<br/>
<strong>Arriving:</strong> date<br/>
<strong>Departing:</strong> date<br/><br/>
Please click here to view your existing reservation(s):<br/>
http://www.somesite.com/index.php?token=WQ85o7OiT9<br/><br/>
Thank You,<br/>
Patti Rea
</div>
</body>
</html>
--b1_9941ff8576a1763200e134b5b313b1b1--