Reputation: 9384
I am using phpMailer library in codeigniter to send html emails,
In this library, i need to load contents and then pass it to some function,
I only find this below method to load view from views in library as a string to assign email 'body' like,
function send_mail($data=array()) {
$mail = new PHPMailer(true);
$this->CI =& get_instance();
$body = $this->CI->load->view('partials/email_template', $data, true);
//setting third parameter to true will convert view to string,
}
Email is being send correctly, but when without images, its only because string cannot contains images if iam not wrong, is there any alternative way to achieve this.
EDIT
Independently to the framework, i am loading contents as,
$body = file_get_contents('email_template.html');
But, this does not work in framework like,
$body = file_get_contents($this->CI->load->view('partials/email_template', $data));
//even setting the third parameter 'true'
and returns me "Message body empty" error..
Many thanks in advance..
Upvotes: 1
Views: 1118
Reputation: 8830
$body = $this->CI->load->view('partials/email_template', $data,true);
This will assign the view file cotent to you variable $body
Upvotes: 0
Reputation: 15619
Because the email is online, it can't just use relative urls and needs to be absolute e.g (http://website.co.uk/partials/email_template/image.png
).
This is because the client getting the e-mail obviously wont have those files local on their computer (or very doubtful).
Upvotes: 0