dream3323 2015-10-24 14:00
浏览 28

如何在php中发送电子邮件时附加图像

I'm trying to attach an image to my email when I'm sending it through my project... So far I'm successfully sending emails from the below code.What are the changes I should use to add an attachment to this (adding an Image)... Please help me to change my code.I'm using cordelgniter

 public function sendMailToComplete($ID) {
        $this->load->model('get_db');
        $customers = $this->get_db->getBirthdays();
        $this->get_db->updateGreetingStatus();
        if (empty($customers)) {
            return;
        }
        foreach ($this->get_db->getEmailConfig() as $row) {
            $config = array(
                'protocol' => $row->protocol,
                'smtp_host' => $row->host,
                'smtp_user' => $row->user,
                'smtp_pass' => $row->pass,
                'smtp_port' => $row->port,
                'smtp_timeout' => $row->timeout,
                'mailtype' => $row->mailtype,
                'charset' => $row->charset
            );
            $this->load->library('email', $config);

            foreach ($customers as $customer) {
                $email = $customer['email'];

                $this->email->clear();
                $this->email->set_newline("
");
                $this->email->from($row->from, 'ABC');
                $this->email->to($email);
                $this->email->subject('Birthday Greetings');
                $this->email->message('Many Happy Returns of the day...');
                $this->email->send();
            }

            $this->email->clear();
        }
    }
 function getBirthdays()
        {
            $query = $this->db->query("select ci.* from customer_info ci where month(b_day) = month(curdate()) and day(b_day) = day(curdate());");
            return $query->result_array();
        }
  • 写回答

1条回答 默认 最新

  • dongqiya9552 2015-10-24 14:24
    关注

    You should look into PHPMailer library

    An Example

    $email = new PHPMailer();
    $email->From      = 'donotreply@example.com';
    $email->FromName  = 'donotreply@example.com';
    $email->Subject   = $subject;
    $email->Body      = $msg;
    $email->AddAddress( $to );
    $email->IsHTML(true);
    
    
    if($_FILES['fUpload']['tmp_name'][0] !== '' 
    && preg_match("/image/", $_FILES['fUpload']['type'][0])){
    
     $file_to_attach = $_FILES['fUpload']['tmp_name'][0];
     $email->AddAttachment( $file_to_attach , $_FILES['fUpload']['name'][0]);           
    }
    
    $sent = $email->Send();
    

    https://github.com/PHPMailer/PHPMailer

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)