Welcome Guest, Not a member yet? Register   Sign In
CI Email Class - Load an html email (view) to send?
#1

[eluser]rt30000[/eluser]
Hello. I did a quick search and didn't find anything.

I would like to have several html email templates throughout my site, depending which form gets submitted. I would like the CI controller to load the requested email/view (and provide it with the message data) and use this for the html email. Possible? Do I just load the view populated with data as the message?

Thanks for any light you can shed on this. I am going to give it a shot, wanted to make sure this was the proper approach.

Rob
#2

[eluser]Pascal Kriete[/eluser]
Sure thing, just add TRUE as a third parameter to the loading call and it will return the view instead of adding it to the output buffer.
Code:
$data['message'] = "Hey there, you've got mail!";
$email = $this->load->view('email/template', $data, TRUE);

Does that make sense?
#3

[eluser]drewbee[/eluser]
To build upon what inparo has said, in the view method, you will see he is passing the third parameter as TRUE. When this happens, the method returns the template data as a string, rather then using it for an output template.
#4

[eluser]rt30000[/eluser]
Thanks guys. It is including the proper file in the email now, but it looks like it's escaping some characters, for example...
Code:
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="bg1">
...comes through as...
Code:
<table width="100%" border="0" cellspacing="0" cellpadding="0" clas=
s="bg1">

Where it is putting extra = signs in and breaking the line. It looks like where double characters are there are two s's, but not in all spots (for example some class tags and the directory 'assets' that come through fine. Thoughts?

Rob
#5

[eluser]drewbee[/eluser]
Hmm. AFAIK, their is no escaping going on. It looks more like a line break then anything. Can you verify their is nothing polluting the html?
#6

[eluser]rt30000[/eluser]
The html file (a php view containing the html email) is perfect. At this point I'm not even sending data into the view, just simply adding the static view as the mail message. The above code is exactly how it exists in the view, and the second is exactly how it comes through in the html email.

This is adding the view:
Code:
$msg = $this->load->view('emails/email-story-submission_view', '', true);
$this->email->message($msg);

When the view is added to the page (for test/preview) it display perfect. When it comes through the mail is when the code is funky.

Here is my config setting if it helps...
Code:
$config['protocol'] = 'mail';
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
#7

[eluser]rt30000[/eluser]
Looked at it more, it appears I am not the only one who has run across this... I'm getting a =3d" periodically throughout the mail result. I have found other threads regarding this, but have yet to find the solution...? What is the fix?

http://ellislab.com/forums/viewthread/75590/
http://ellislab.com/forums/viewthread/89196/
#8

[eluser]drewbee[/eluser]
Do you use the configuration file?

Is your configuration file named 'Email.php', or 'email.php' (with the later being a lowercase 'e')??
#9

[eluser]andreagam[/eluser]
Rt30000, I ran across this issue some time ago.
This thread might be of some help.

http://ellislab.com/forums/viewthread/86654/

Bye,

Andrea
#10

[eluser]rt30000[/eluser]
Yes, my config/email.php has a lowercase 'e'. It appears to be working, becuase it was originally set to text format and I changed it to html and it seemed to work. The following is the code I have in it. The crlf and newline have helped the line breaks in my received email, but the =3d" issue persists and I cannot figure it out. I will paste the code below the config code...
email config (email.php)
Code:
&lt;?php
$config['protocol'] = 'mail';
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
?&gt;

Email Source in inbox:
Code:
&lt;html&gt;
&lt;head&gt;
    &lt;meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"&gt;
    &lt;title&gt;Lakeside Story Submission&lt;/title&gt;
    &lt;link rel=3D"stylesheet" type=3D"text/css" href=3D"http://lakeside.shift2d=
esign.com/assets/img/email/story-submission/screen.css"&gt;
&lt;/head&gt;
&lt;body&gt;
<table width=3D"100%" border=3D"0" cellspacing=3D"0" cellpadding=3D"0" clas=
s=3D"bg1">
    <tr>
        <td align=3D"center">
            <table width=3D"600" border=3D"0" cellspacing=3D"0" cellpadding=3D"0" cl=
ass=3D"bg2">
                <tr>
                    <td class=3D"header" align=3D"left">
                        <img >
                    </td>
                </tr>
                <tr>
                    <td valign=3D"top" class=3D"body">
                        <table width=3D"100%" border=3D"0" cellspacing=3D"0" cellpadding=3D"0=
">
                            <tr>
                                <td valign=3D"top" class=3D"mainbar" align=3D"left">
                                    <h2>Lakeside Story Submission</h2>
                                    <img
>
                                    <p>From: <strong>gggg</strong><br />
                                        Email: <strong><a >gg</a></strong></p>
                                    <h3>Title:</h3>
                                    <p>ggg</p>
                                    <h3>Story:</h3>
                                    <p>ggg</p>
                                    <br>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign=3D"middle" align=3D"left" class=3D"footer" height=3D"61">
                        <p>Tue, 04 Nov 08 12:07:05 -0700&nbsp;&nbsp;|&nbsp;&nbsp;<a >www.lakesideohio.com</a></p>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
</table>
&lt;/body&gt;
&lt;/html&gt;

--B_ALT_49109d5913550--




Theme © iAndrew 2016 - Forum software by © MyBB