【问题标题】:How to display an image in email in codeigniter?如何在codeigniter的电子邮件中显示图像?
【发布时间】:2018-12-10 16:08:11
【问题描述】:
      $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;" />')

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    方法 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)
    

    【讨论】:

      【解决方案2】:

      我不确定其他答案是否有效,但最新的 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 并将其内联显示在电子邮件正文的任何​​位置。

      【讨论】:

        【解决方案3】:

        感谢阿卜杜拉的帮助。我尝试了以下不同的方式。

        $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(); 
        

        【讨论】:

          猜你喜欢
          • 2016-08-02
          • 2011-04-03
          • 2011-09-06
          • 2020-08-20
          • 2012-06-23
          • 2011-10-17
          • 1970-01-01
          • 2018-02-12
          • 2013-04-27
          相关资源
          最近更新 更多