以下是我的$message
变量,其中我为html电子邮件执行了内联样式,但问题是电子邮件正在发送附件,但样式未应用并按原样发送整个代码。请告诉我如何解决此问题,以便发送HTML样式的电子邮件?
$message = '<html><body>';
$message .= '<img src="http://webi.com/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table width="100%"; rules="all" style="border:1px solid #3A5896;" cellpadding="10">';
$message .= "<tr><td><img src='http://www.phpgang.com/wp-content/uploads/gang.jpg' alt='PHP Gang' /></td></tr>";
$message .= "<tr><td colspan=2>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" . strip_tags($_POST['fname']) . "</td></tr>";
$message .= "<tr><td><strong>Last Name:</strong> </td><td>" . strip_tags($_POST['lname']) . "</td></tr>";
$message .= "<tr><td><strong>Address:</strong> </td><td>" . $_POST['address'] . "</td></tr>";
$message .= "</table>";
$message .= "</td></tr>";
$message .= "<tr><td colspan=2 font='colr:#999999;'><I>PHPGang.com<br>Solve your problem. :)</I></td></tr>";
$message .= "</table>";
$message .= "</body></html>";
// Now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// Next, we'll build the message body note that we insert two dashes in front of the MIME boundary when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$file_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" file=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
答案 0 :(得分:0)
您可以尝试将Content-Type设置为text / html,看看是否有效。
但是如果你想发送复杂的电子邮件(例如附件或HTML!)那么你可以使用phpmailer-class。
它易于实现和使用。您可以查看示例文件夹中给出的示例。然后,您可以以非常简单的方式发送HTML-Mails。