我正在尝试将特定 div 的 innerhtml 发送到电子邮件(在 Codeigniter 框架中)。
我使用 jquery 获取了 div 的内部 html,并使用 ajax 将数据传输到 Controller 。
邮件有效,但我的问题是 html 类、样式标签(我在 View 文件 html 中编写的内联样式除外)、样式表不起作用。
有什么办法可以加我的style.css
电子邮件内容中的文件?即使我在 <head>
开头放置的标签正常工作,我也会没事的部分。
请帮忙,这是我的代码。
用于将 html 传输到 Controller 的 Ajax 代码:
<script type="text/javascript">
$(function() {
$('#sendmail').click(function(e) {
e.preventDefault();
$.ajax({
url:'<?php echo site_url();?>/welcome/send',
type:'POST',
data:{'message':$('#body').html(),'subject':'Subject of your e-mail'},
success:function(data) {
alert('You data has been successfully e-mailed');
alert('Your server-side script said: ' + data);
}
});
});
});
</script>
Controller 中的代码 公共(public)函数发送() {
$nome = $this->input->post('message');
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'send.one.com',
'smtp_port' => '2525',
'smtp_user' => 'akhil.ns@cymose-tech.com',
'smtp_pass' => 'akhil123',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'mailtype' => 'html'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('akhil.ns@cymose-tech.com', 'The Wanderers');
$this->email->to('shabasy002@gmail.com');
$this->email->subject('The Wanderers Proforma Invoice ');
$formatedMessag ='';
$formatedMessag = '<html><head><link rel="stylesheet" type="text/css" href="http://localhost/study/extra/style.css"></head><body><style type="text/css">p{color:#cccccc;font-weight:bold;}</style>';
$formatedMessag .= $nome.'</body></html>';
$this->email->message($formatedMessag);
if ($this->email->send()) {
echo $formatedMessag;
}
}
最佳答案
据我所知,没有电子邮件客户端允许为 HTML 电子邮件加载外部样式表。
最终,这意味着您必须在文档的头部声明样式,例如
<head>
<style>
body { background: black; color: white; }
</style>
</head>
但是,一些电子邮件客户端(好吧,几乎就是 outlook)甚至不允许在文档的头部定义一些样式,这意味着内联样式如下:
<body style="background: black; color: white;"></body>
(我内心的一点点刚刚死去)
即使在 HTML 电子邮件中使用内联 CSS 也存在许多问题,因为一些客户端(同样主要是 outlook)不支持简单的 CSS 功能,如 float。这最终意味着您必须使用表格对时事通讯进行编码,以确保它适用于大多数人。
有关更多信息,请参阅这篇文章(或仅谷歌一下): http://www.sitepoint.com/code-html-email-newsletters/
关于html - Codeigniter 电子邮件 - 样式标签/CSS 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13820595/