I've never had issues sending emails before through CodeIgniter, but all of a sudden it's an issue on my latest project.
I'm using this mail server tool to send mail on my local-host, which has never given me any issues before, and then the CodeIgniter email library.
I can get one of 2 results: either the email sends, but all the raw HTML source code is displayed, or the email sends and has a subject line, but the entire body is blank.
This is my email_helper.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');
function send_email($to, $subject, $template)
{
$ci = &get_instance();
$ci->load->library('email');
$config = array(
'mailtype' => 'html',
'newline' => '\r\n',
'crlf' => '\r\n'
);
//If I comment out this line, it sends raw HTML, otherwise it sends a blank body.
$ci->email->initialize($config);
$ci->email->from($ci->config->item('from_email_address'), $ci->config->item('from_email_name'));
$ci->email->reply_to($ci->config->item('from_email_address'), $ci->config->item('from_email_name'));
$ci->email->to($to);
$ci->email->subject($subject);
$ci->email->message($ci->load->view('email/' . $template . '_html', $data, TRUE));
$ci->email->send();
}
this is my test_html.php
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<div style="max-width: 800px; margin: 0; padding: 30px 0;">
TEST!
</div>
</body>
</html>
And then I'm calling the email helper from my controller with this:
$this->load->helper('email_helper');
send_email($this->input->post('email'), 'Test Subject', 'test');