簡體   English   中英

如何在Codeigniter中的電子郵件中顯示圖像?

[英]How to display an image in email in 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();

嘗試在消息中包含在內,還嘗試作為內聯附件,但兩者均無效。 我需要的是在發送電子郵件並打開它時,應該可以看到該圖像。

目前,我收到以下電子郵件

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

方法01(Codeigniter)

將圖像上傳到您的服務器。

發送電子郵件的控制器中 ,添加以下行:

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

然后在電子郵件視圖中添加以下內容:

<img src="cid:location-of-file.png" border="0">

並且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)

感謝阿卜杜拉的幫助。 我嘗試了以下不同方式。

$ mail_body = $ this-> load-> view('email_template / promo_email',$ data,TRUE);

    $this->load->library('email');
    $config['mailtype'] = 'html';
    $this->email->initialize($config);

    $this->email->from('another@another-example.com', 'Admin');
    $this->email->to('them@their-example.com'); 

    $this->email->subject($subject.' Promotion');
    $this->email->message($mail_body);

     $this->email->send(); 

我不確定其他答案是否可行,但是最新的3.1.9幾乎沒有什么不同,我只是對其進行了測試。

https://www.codeigniter.com/user_guide/libraries/email.html

$filename = '/img/photo1.jpg';
$this->email->attach($filename);
foreach ($list as $address)
{
        $this->email->to($address);
        $cid = $this->email->attachment_cid($filename);
        $this->email->message('<img src="cid:'. $cid .'" alt="photo1" />');
        $this->email->send();
}

文件名是服務器上文件的完整路徑。 首先,您附加文件,然后獲取文件的cid,並將其內聯顯示在電子郵件正文中的任何位置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM