2

I have created an HTML page with inline css and provided logo as inline css background

<div id="logo_image" style='background: url("<?=base_url();?>assets/images/img2.png") no-repeat scroll 0 0 / 150px auto rgba(0, 0, 0, 0);height: 73px;margin: -15px 0 0;position: absolute; width: 160px;'></div>

I have also tried using

<img src="<?=base_url();?>assets/images/img2.png" style="float: left;margin-top: -11px;width: 100px;margin-left:10px;" />

The mail function used is as below

$this->email->clear();
$this->email->set_newline("\r\n");

$this->email->set_mailtype("html");
$this->email->from('example@gmail.com','example');

$this->email->to($user['email']);
$this->email->subject('Thank You');
$this->email->message($this->load->view('emails/register', $name, TRUE));

$name contains some variables to be displayed in the template register.php

Everything works well except for logo not being displayed

P.S. : i am working on localhost.

dhpratik
  • 1,100
  • 4
  • 19
  • 43

2 Answers2

2

the answer is in ur own question. you are sending mail from localhost/ur localmachine. when u send mail with image or imported css or js which are on ur localmachine, gmail or anyother cannot interprete that as a proper url.

so what it does is appends its own url before it like https://ci3.googleusercontent.com/proxy/..some link..#http://localhost/assets/images/img2.png

so ur image will not be displayed until you upload the project on a domain.

dhpratik
  • 1,100
  • 4
  • 19
  • 43
1

Instead of using:

<img src="<?=base_url();?>assets/images/img2.png" style="float: left;margin-top: -11px;width: 100px;margin-left:10px;" />

try using:

<img src="<?php echo base_url();?>assets/images/img2.png" style="float: left;margin-top: -11px;width: 100px;margin-left:10px;" />

I replaced <?= ... ?> with the full php tag <?php ?>.

I know that it causes problems sometimes, so I always use the full tag.

Renier
  • 1,523
  • 4
  • 32
  • 60
  • oh yeah... sorry.. forgot to change that... I'll edit – Renier Dec 10 '13 at 08:36
  • try viewing the source of the email, then check if the link to the image is 1, correct, and 2, if it takes you to the image when you go to that link. that is the only other reason I can think of that its not working. – Renier Dec 10 '13 at 08:59
  • if i send mail to gmail id, it prepends its on url to my link. – dhpratik Dec 10 '13 at 09:29
  • @dhpratik The reason not use the short tags: `=""asdf";?>` is. And I quote from this [post](http://stackoverflow.com/questions/200640/are-php-short-tags-acceptable-to-use):"To answer the why part, I'd quote Zend PHP 5 certification guide: "Short tags were, for a time, the standard in the PHP world; however, they do have the major drawback of conflicting with XML headers and, therefore, have somewhat fallen by the wayside."" Regardless of the fact that it does the same, it is better practice to use the full tag: ``. – Renier Dec 10 '13 at 10:52