如何在codeigniter中显示电子邮件中的图像?

San*_*tha 3 php codeigniter

      $this->load->library('upload');
      $this->load->library('email');
      $this->email->set_newline("\r\n");
      $this->email->from($email);
      $this->email->to($cus_email);
      $this->email->subject($promo_name.' Offers');
      $this->email->message($remarks.'/n <img src="<?php echo base_url();?>images/promotions/<? echo $image; ?>" style="float: left;margin-top: -11px;width: 100px;margin-left:10px;" />');


     // $this->email->attach($img,'inline');
    // $this->email->attach($img);
       $this->email->send();
Run Code Online (Sandbox Code Playgroud)

尝试包含在消息中,也尝试作为内联附件,但两者都不起作用。我需要的是当发送电子邮件并打开它时,应该看到图像。

目前我收到如下电子邮件

$remarks.'/n <img src="<?php echo base_url();?>images/promotions/<? echo $image; ?>" style="float: left;margin-top: -11px;width: 100px;margin-left:10px;" />')
Run Code Online (Sandbox Code Playgroud)

Abd*_*lam 5

方法01(代码点火器)

将图像上传到您的服务器。

发送电子邮件的控制器中,添加以下行:

$this->email->attach("/home/yoursite/location-of-file.jpg", "inline");
Run Code Online (Sandbox Code Playgroud)

然后在电子邮件视图中添加以下内容:

<img src="cid:location-of-file.png" border="0">
Run Code Online (Sandbox Code Playgroud)

并将location-of-file.jpg更改为该资源的内容 ID。

其他事情也可以工作,例如...src=",,...href="url('')

方法02(标准)

$to = 'receiver@gmail.com';
$subject = 'Mail With Inline Image';

$message = 'This is first line';
$message .= 'This is Second line';
$message .= '<img src="http://example.com/images/filename.jpg" alt="my picture">';

$header = 'MIME-Version: 1.0';
$header .= 'Content-Type: text/html; charset="ISO-8859-1';

mail($to, $subject,$message,$header)
Run Code Online (Sandbox Code Playgroud)