Codeigniter email - tag style / css not working

I am trying to send innerhtml of a specific div to email (as part of Codeigniter).

I got the internal html div using jquery and passed the data to the controller using ajax.

Mail worked, but my problem is html classes, style tags (except for the inline styles that I wrote in the view html file), the stylesheet does not work.

Can I add a style.css file to style.css email content? I will be fine, even if the tag works correctly, which I put at the beginning of the <head> section.

Please help, here is my code.

Ajax code to transfer html to the controller:

 <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> 

The code in the controller is the public function send () {

  $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; } } 
+4
source share
2 answers

As far as I know, no email clients allow you to download external stylesheets for HTML emails.

Ultimately, this means that you must declare styles at the beginning of the document, for example.

 <head> <style> body { background: black; color: white; } </style> </head> 

However, some email clients (well, basically, just the look) do not even allow some of the styles defined in the document header, which means nesting styles, such as:

 <body style="background: black; color: white;"></body> 

(a little inside of me just died)

There are also a number of problems with using even embedded CSS in HTML emails, as some clients (again mainly Outlook) do not support simple CSS functions, such as float. Which ultimately means that you need to code the newsletter with tables to make sure that it works for most people.

For more information, see this article (or just Google): http://www.sitepoint.com/code-html-email-newsletters/

+3
source

The problem is that you can only use inline and internal css, this means that you can define all css rules right inside the element, e.g.

 <td style="padding:10px;"><b style="color:red;">Texty</b></td> 

or in the <head></head> your email document:

 <head> <style> b {color:red;} td { padding:10px; } </style> </head> 
0
source

All Articles