在 codeigniter 中使用 bootstrap 发送 HTML 电子邮件
send HTML email with bootstrap in codeigniter
我想使用 codeigniter 发送 HTML 电子邮件。它确实有效,但没有按照我希望的方式显示。我希望它看起来像这样
但它在我的电子邮件中显示为纯文本和 link。我该如何解决这个问题?
这是我的代码(emailhtml 视图):
<!DOCTYPE HTML>
<html>
<head>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="row" >
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
Hi User,
</div>
<div class="modal-body">
This is your final step to complete your registration.
Please confirm your email address - just click on the button below.
<a href="http://localhost/MyProject/index.php/Registration/" class="btn btn-primary">Confirm Now</a>
</div><!--END of modalb-->
</div><!--END of mod-cont-->
</div><!--END of mod-Dia-->
</div><!--END of row-->
</body>
</html>
在控制器中:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx@gmail.com',
'smtp_pass' => '*****',
'wordwrap' => true
);
//load email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
//set email information and content
$this->email->from('xxxx@gmail.com', 'My Name');
$this->email->to($email);
$this->email->subject('Confirmation for Registration');
$this->email->message($this->load->view('admin/EmailHTML', $data,true));
$this->email->set_mailtype('html');
$this->email->send();
非常感谢您的帮助。
很少有电子邮件客户端接受 link 到外部 CSS 文件,事实上,甚至有一些不接受嵌入式样式表。 (CSS support for email clients)
最好的办法是内联所有样式。虽然这是一个很好的解决方案,但这可能不能保证您的样式会被接受,因为支持因客户而异(见上文 link)。有一些内衬可能对您有帮助(Zurb and MailChimp 应该是最好的)。
随着移动设备成为 HTML 电子邮件查看的新常态,内联所有样式可能会导致移动设备显示出现问题。为了解决这个问题,新的理论是首先为移动设备设计,然后使用 MSO 条件语句和嵌入式样式表在桌面客户端上显示。 (Good article on this approach)
我想使用 codeigniter 发送 HTML 电子邮件。它确实有效,但没有按照我希望的方式显示。我希望它看起来像这样
但它在我的电子邮件中显示为纯文本和 link。我该如何解决这个问题?
这是我的代码(emailhtml 视图):
<!DOCTYPE HTML>
<html>
<head>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="row" >
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
Hi User,
</div>
<div class="modal-body">
This is your final step to complete your registration.
Please confirm your email address - just click on the button below.
<a href="http://localhost/MyProject/index.php/Registration/" class="btn btn-primary">Confirm Now</a>
</div><!--END of modalb-->
</div><!--END of mod-cont-->
</div><!--END of mod-Dia-->
</div><!--END of row-->
</body>
</html>
在控制器中:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'tls://smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxx@gmail.com',
'smtp_pass' => '*****',
'wordwrap' => true
);
//load email library
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
//set email information and content
$this->email->from('xxxx@gmail.com', 'My Name');
$this->email->to($email);
$this->email->subject('Confirmation for Registration');
$this->email->message($this->load->view('admin/EmailHTML', $data,true));
$this->email->set_mailtype('html');
$this->email->send();
非常感谢您的帮助。
很少有电子邮件客户端接受 link 到外部 CSS 文件,事实上,甚至有一些不接受嵌入式样式表。 (CSS support for email clients)
最好的办法是内联所有样式。虽然这是一个很好的解决方案,但这可能不能保证您的样式会被接受,因为支持因客户而异(见上文 link)。有一些内衬可能对您有帮助(Zurb and MailChimp 应该是最好的)。
随着移动设备成为 HTML 电子邮件查看的新常态,内联所有样式可能会导致移动设备显示出现问题。为了解决这个问题,新的理论是首先为移动设备设计,然后使用 MSO 条件语句和嵌入式样式表在桌面客户端上显示。 (Good article on this approach)