I am trying to send innerhtml of a particular div to email(in Codeigniter framework).
I got the inner html of the div using jquery and transfered the data to the controller using ajax.
The mail worked, but my problem is html classes, style tags(except the inline styles i wrote in the view file html), style sheet are not working.
Is there any way to add my style.css file in the email content? I will be ok even if the tag works properly, which I had put at the begining of the <head> section.
Please help, here is my code.
Ajax code for transfering html to 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>
Code in the controller
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;
}
}
As far as I know, no email clients allow loading of external stylesheets for HTML emails.
Ultimately, this means that you have to declare the styles in the head of the document, e.g.
However, some email clients (Well, pretty much just outlook) don’t even allow some styles defined in the head of the document, which means inlining styles like such:
(a little bit of me inside just died)
There are also a number of problems with using even inline CSS in HTML emails as some clients (again mostly outlook) don’t support simple CSS features like float’s. Which ends up meaning you have to code the newsletter with tables to ensure it works for the majority of people.
For more information see this article (or just Google around):
http://www.sitepoint.com/code-html-email-newsletters/