Welcome Guest, Not a member yet? Register   Sign In
How to include email view as email message?
#1

[eluser]Christophe28[/eluser]
Hi,

I would like to include the 'email/activate_html.php' view as message using the CI email class, but it doesn't work?

My code:

Code:
// load email library
$this->load->library('email');
                
// send activation email
$this->email->from('[email protected]', 'website');
$this->email->to($data['email']);

$this->email->subject('Account activation');
$this->email->message($this->load->view('email/activate_html'));    

$this->email->send();

When using this code the email message is empty and the view is being load on the 'success page' just after registration.

However I saw the same solution in an other auth library:

Code:
function _send_email($type, $email, &$data)
    {
        $this->load->library('email');
        $this->email->from($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
        $this->email->reply_to($this->config->item('webmaster_email', 'tank_auth'), $this->config->item('website_name', 'tank_auth'));
        $this->email->to($email);
        $this->email->subject(sprintf($this->lang->line('auth_subject_'.$type), $this->config->item('website_name', 'tank_auth')));
        $this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));
        $this->email->set_alt_message($this->load->view('email/'.$type.'-txt', $data, TRUE));
        $this->email->send();
    }

Any suggestions?

Thx!

Christophe
#2

[eluser]umefarooq[/eluser]
hi check are you call right file name you want to include email/activate_html.php but in your code

Code:
$this->email->message($this->load->view('email/'.$type.'-html', $data, TRUE));

change to

$this->email->message($this->load->view('email/'.$type.'_html', $data, TRUE));

or before sending email check your view output

echo $this->load->view('email/'.$type.'_html', $data, TRUE);

hope it will work
#3

[eluser]Christophe28[/eluser]
Hi,

No, I just gave the second portion of code as an example which worked. The first code block is my own code block which don't work. The view is set correct, but isn't send along with the email, but load after submitting the form ...

Still working on it, but still haven't find a solution, so if anybody could help me out here, that would be great! Smile

Christophe
#4

[eluser]markup2go[/eluser]
As umefarooq posted, when you use the loader class, particularly the view method, in your case you want to return a string so you would set the 3rd parameter to TRUE. This will return data as a string rather then rendering it to your browser.




Theme © iAndrew 2016 - Forum software by © MyBB