我正在尝试发送HTML格式的发票,但它是以纯文本而不是格式化的HTML发送邮件。
代码是:
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('sample@email.com', 'Sample');
$this->email->to('sample2@email.com');
$this->email->cc('sample3@email.com');
$this->email->subject('Sample Test');
$this->email->message($message);
$this->email->send();
echo $this->email->print_debugger();
和内容:
$message ='
<!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">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style>
<![CDATA[
body, td { color:#a6a7a3; font-size: 14px; font-family:Arial; font-weight:normal; text-decoration:none; }
a { color:#a6a7a3; font-weight:normal; text-decoration:none; }
table td { border-collapse: collapse;}
]]>
</style>
</head>
<body>
<table>
<tr>
<td>
<table>
<tr>
<td>
<!-- // Begin Template Header \ -->
<table>
<tr>
<td><!--IMAGE--></td>
</tr>
</table><!-- // End Template Header \ -->
</td>
</tr>
<tr>
<td>
<!-- // Begin Template Body \ -->
<table>
<tr>
<td>
<!-- // Begin Module: Standard Content \ -->
<table>
<tr>
<td>
<div>
<strong style="font-size:14px;font-family:Arial;">Dear Sample,</strong><br />
<br />
Thank you for being with us. <!-- Start Transaction Information -->
<table>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><strong>Sample</strong></td>
</tr>
</table>
<table>
<tr>
<td></td>
</tr>
<tr>
<td>Item Name</td>
<td>Quantity</td>
<td>Item Price</td>
<td>Item Code</td>
<td>Shipping</td>
</tr>
<tr>
<td>'.$item.'</td>
<td>'.$quantity.'</td>
<td>'.$price.'</td>
<td>'.$code.'</td>
<td>'.$shipping.'</td>
</tr>
</table><!-- End Transaction Information -->
</div>
</td>
</tr>
</table><!-- // End Module: Standard Content \ -->
</td>
</tr>
</table><!-- // End Template Body \ -->
</td>
</tr>
</table><br />
</td>
</tr>
</table><br />
</body>
</html>';
答案 0 :(得分:1)
$this->email->set_mailtype("html");
在这里你也可能会觉得这很有用..我很无聊。您将获得与此代码更好的设备兼容性。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="telephone=no" name="format-detection" /><!-- ios -->
<meta content="on" http-equiv="cleartype" /><!-- Internet explorer -->
<style>
<![CDATA[
html,body,.ReadMsgBody, .ExternalClass,.ExternalClass * { background-color:#ffffff;width:100%!important;line-height:100%;margin:0;-webkit-text-size-adjust:100%; }
table,table td { border-collapse:collapse;mso-table-lspace:0pt;mso-table-rspace:0pt; }
img { display:block;border:0 none;outline:none;height:auto;line-height:100%;margin:0;padding:0;text-decoration:none;-ms-interpolation-mode:bicubic; }
.container { width:600px; }
#outlook a { padding:0; }
.yshortcuts,.yshortcuts a,.yshortcuts a:link,.yshortcuts a:visited,.yshortcuts a:hover,.yshortcuts a span { color:#a6a7a3;text-decoration:none!important;border-bottom:none!important;background:none!important;}
]]>
</style>
<title></title>
</head>
<body bgcolor="#FFFFFF" style="min-width:100%;margin-top:0;margin-bottom:0;margin-left:0;margin-right:0;padding-top:0;padding-bottom:0;padding-left:0;padding-right:0;color:#a6a7a3;font-family:Arial,sans-serif;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!-- // Begin Template Header \ -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td><!--IMAGE (style-display:block;!!)--></td>
</tr>
</table><!-- // End Template Header \ -->
</td>
</tr>
<tr>
<td>
<!-- // Begin Template Body \ -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<!-- // Begin Module: Standard Content \ -->
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="color:#a6a7a3;font-size:14px;font-family:Arial,sans-serif;text-align:left;">
<b>Dear Sample,</b><br />
</td>
</tr>
<tr>
<td style="color:#a6a7a3;font-size:14px;font-family:Arial,sans-serif;text-align:left;">
Thank you for being with us. <!-- Start Transaction Information -->
</td>
</tr>
<tr>
<td style="color:#a6a7a3;font-size:14px;font-family:Arial,sans-serif;text-align:left;">
<b>Sample</b>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="3" cellspacing="0"><tr><td height="3"><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr></table></td></tr></table>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">Item Name</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">Quantity</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">Item Price</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">Item Code</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">Shipping</td>
</tr>
<tr>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">'.$item.'</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">'.$quantity.'</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">'.$price.'</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">'.$code.'</td>
<td style="text-align:left;font-family:Arial,sans-serif;font-size:14px;color:#a6a7a3;">'.$shipping.'</td>
</tr>
</table><!-- End Transaction Information -->
</td>
</tr>
</table><!-- // End Module: Standard Content \ -->
</td>
</tr>
</table><!-- // End Template Body \ -->
</td>
</tr>
</table>
</body>
</html>