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