php - Codeigniter 发送带有附件的电子邮件

标签 php codeigniter email email-attachments

我正在尝试在 codeigniter 上发送带有附件的电子邮件。

我总是能成功收到邮件。但是,我从来没有收到过附加文件。以下是代码,非常感谢所有评论。

    $ci = get_instance();
    $ci->load->library('email');
    $config['protocol'] = "smtp";
    $config['smtp_host'] = "ssl://smtp.gmail.com";
    $config['smtp_port'] = "465";
    $config['smtp_user'] = "test@gmail.com";
    $config['smtp_pass'] = "test";
    $config['charset'] = "utf-8";
    $config['mailtype'] = "html";
    $config['newline'] = "\r\n";

    $ci->email->initialize($config);

    $ci->email->from('test@test.com', 'Test Email');
    $list = array('test2@gmail.com');
    $ci->email->to($list);
    $this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
    $ci->email->subject('This is an email test');
    $ci->email->message('It is working. Great!');

    $ci->email->attach( '/test/myfile.pdf');
    $ci->email->send();

最佳答案

$this->email->attach()

使您能够发送附件。将文件路径/名称放在第一个参数中。注意:使用文件路径,而不是 URL。对于多个附件,请多次使用该功能。例如:

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

    }

关于php - Codeigniter 发送带有附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25416585/

相关文章:

php - CodeIgniter 路径常量定义

java - 求助关于AndroidManifest.xml读取问题

PHP 文件 - 导出 xls 而不是 csv

php - 使用 PHP 排序 MySQL 数据

php - Codeigniter:加载 session 库时出现错误

php - 动态表单、PHP 和 MYSQL

php - 尝试通过制作可重用功能来减少代码点火器中的代码

php - 代码点火器 : Run a script from command line if the controller is inside a folder?

c# - 使用 Windows 虚拟邮件服务器发送带有 header 返回路径的电子邮件

google-app-engine - 使用 Google App Engine 自定义传入邮件域