Codeigniter send email with attach file

前端 未结 8 1512
走了就别回头了
走了就别回头了 2020-11-30 05:15

I am trying to send email on codeigniter with attach file.

I always receive email successfully. However , I never receive with attach file. Below is code and highly

相关标签:
8条回答
  • 2020-11-30 05:49

    $this->email->attach()

    Enables you to send an attachment. Put the file path/name in the first parameter. Note: Use a file path, not a URL. For multiple attachments use the function multiple times. For example:

    public function setemail()
    {
    $email="xyz@gmail.com";
    $subject="some text";
    $message="some text";
    $this->sendEmail($email,$subject,$message);
    }
    public function sendEmail($email,$subject,$message)
        {
    
        $config = Array(
          'protocol' => 'smtp',
          'smtp_host' => 'ssl://smtp.googlemail.com',
          'smtp_port' => 465,
          'smtp_user' => 'abc@gmail.com', 
          'smtp_pass' => 'passwrd', 
          'mailtype' => 'html',
          'charset' => 'iso-8859-1',
          'wordwrap' => TRUE
        );
    
    
              $this->load->library('email', $config);
              $this->email->set_newline("\r\n");
              $this->email->from('abc@gmail.com');
              $this->email->to($email);
              $this->email->subject($subject);
              $this->email->message($message);
                $this->email->attach('C:\Users\xyz\Desktop\images\abc.png');
              if($this->email->send())
             {
              echo 'Email send.';
             }
             else
            {
             show_error($this->email->print_debugger());
            }
    
        }
    
    0 讨论(0)
  • 2020-11-30 05:49

    use path helper

    $this->load->helper('path');
    $path = set_realpath('./images/');
    

    on email line

    $this->email->attach($path . $your_file);
    
    0 讨论(0)
提交回复
热议问题