Im trying to render emails on my site. The problem is that these emails contains html and css, which means that I suddenly can get a green background on the page. its not rendering the mail properly. Sometimes I see html tags and so on.( se picture in the link below)
I hade my thoughts on iframe. But as you can see i dont have a link refere to in the iframe src parameter.
This is parts the code that im using (MVC)
This is the Model function that im using
function get_mail_num($email_number)
{
$connection = imap_open($this->server, $this->user, $this->password);
$mail['overview'] = imap_fetch_overview($connection,$email_number,0);
$mail['message'] = imap_fetchbody($connection,$email_number,2);
imap_close($connection);
return $mail;
}
This is the controller function that are featching the mails and sending them to the view
function index() // the inbox
{
$this->load->model('mail_model');
$this->load->library('pagination');
$this->load->library('table');
// config for table
$config['total_rows'] = $this->mail_model->get_size();
$config['per_page'] = 10;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['base_url'] = 'http://nullpointer.se/mailendar/mail/index';
$config['num_links'] = 4;
if(!$this->uri->segment(3)){$offset = 1;}else{$offset = $this->uri->segment(3);}
$records = $this->mail_model->get_mail_header($config['per_page'],$offset);
$data['output'] ="";
$id = $offset;
for($i = 0; $i < count($records);$i++)
{
if(empty($records[$i]->subject))
{
$records[$i]->subject = "No Subject";
}
$data['output'].= '<div onclick="funct('.$id.')" class="toggler '.($records[$i]->seen ? 'read' : 'unread').'">';
$data['output'].= '<span class="subject">'.$records[$i]->subject.'</span> ';
$data['output'].= '<span class="from">'.$records[$i]->from.'</span>';
$data['output'].= '<span class="date">on '.$records[$i]->date.'</span>';
$data['output'].= '</div>';
$data['output'].= "<div class='body' id ='{$id}'> </div>";
$id++;
}
$this->pagination->initialize($config);
$data['page'] = "pages/mail";
$this->load->view('includes/template',$data);
}
This is the view that shows everything
<div id="main" class="span-19 last colborder">
<h2>Mail</h2>
<?php echo $output//$this->table->generate(); ?>
<?php echo $this->pagination->create_links(); ?>
</div>
<div id = "sidebar" class = "span-4 last">
<h2>Options</h2>
<a href = "Convert" class ="button">Convert</a>
<a href = "Remove" class ="button">Remove</a>
<a href = "Move" class ="button">Move</a>
</div>
You probably mentioned the easiest solution. You could simply create a simple email viewer, ex: viewer.php?id=123 for email id 123, then display the viewer through a simple iframe:
All you need to do in your viewer is to get the email body from your model, the echo it.