Welcome Guest, Not a member yet? Register   Sign In
Inline image in HTML emails
#1

[eluser]Unknown[/eluser]
I have modified the email class (Email.php) to include basic support for inline image attachments.
A few caveats:
- If you want to display an image inline, it must be attached (simple enough using email->attach($file))
- Like with everything, no email service was created equal...even though we have RFCs (see my screen shots of hotmail, gmail, and yahoo. Note that yahoo violates, imo, the unspoken rule of auto-loading attached images but yet not auto-loading non-attached images)
- To reference an attached image in your HTML page, use cid:filename.ext, note the cid:

Can someone run a diff with the latest CI Email.php and my Email.php so me/we can see what was changed? I changed a lot, but some changes may not be necessary.

Edit: Since I can't post ANY of the attachments, you can download copies off my server.
http://code.datanethost.net/

Sample code:
Code:
$this->load->library('email');
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$data["body"] = '<b><img src="cid:img.png" />';
$this->email->attach(getcwd() . '/img.png');
$emailbody = $this->load->view('mail_view.php',$data,true);
$this->email->subject('Email Test');
$this->email->message($emailbody);    

$this->email->send();

echo $this->email->print_debugger();

If my changes get merged into the official release of CI, all I ask for is credit somewhere; not necessarily in the Email.php file.
#2

[eluser]Unknown[/eluser]
Good Job adamsna! It worked very well for me!

It is a good tool for mail marketing.

Thanks.
#3

[eluser]Unknown[/eluser]
Worked excellently
#4

[eluser]Karim Ainine[/eluser]
I took a look at the first post's code and I modified it to allow both inline and regular attachments. Replace the Email.php file with the one attached. Then in the controller, use
Code:
$this->email->attach($file['file'],'inline'); // for the embeded images
or
Code:
$this->email->attach($file['file']); // for the other attachments

In the message, refer to the image normally using
Code:
<img src='cid:filename.ext'/>
#5

[eluser]InsiteFX[/eluser]
And if I replace the Email class with the one you have what do you think is going to happen when CI comes out with a new version and I copy the system directory over?

You never modifiy a system library you extend them!!!

Code:
MY_Email extends CI_Email {

}

If the library you are extending is in ./system/core then it goes in ./application/core
If the library you are extending is in ./system/libraries then it goes in ./application/libraries
#6

[eluser]Karim Ainine[/eluser]
Fair enough.. my bad...

Just add the attached code to application/libraries/MY_Email.php and use the same code I mentioned earlier to get inline images in the email.
#7

[eluser]Dan Tdr[/eluser]
could you repost the class only with the extended functions? i don`t want to extend all the functions in the class email, and i do not know what you modified in the class.

Thank you




Theme © iAndrew 2016 - Forum software by © MyBB