【问题标题】:send email with attachment in CodeIgniter在 CodeIgniter 中发送带有附件的电子邮件
【发布时间】:2018-05-23 05:58:32
【问题描述】:

在 CodeIgniter 我的源代码中通过电子邮件发送 PDF 附件

  $this->load->library('email', $config);
  $this->email->set_newline("\r\n");
  $this->email->from('test@gmail.com'); 
  $this->email->to($useremail);
  $this->email->cc('');
  $this->email->subject('pdf');
  $this->email->message($message);
  $this->email->attach('public_html/invoicepdf/171.pdf');
  $mailsucc =   $this->email->send();

我试过了,但没用

$this->email->attach('public_html/invoicepdf/171.pdf');

我还用 URL 替换路径。

【问题讨论】:

  • 用户 FCPATH , $this->email->attach(FCPATH.'/path/to/photo1.jpg');

标签: codeigniter email codeigniter-3 email-attachments


【解决方案1】:

您可以使用发送附件文件

$this->email->attach($atch);

codeigniter 中的方法。在下面的代码中,我使用 SMTP 发送邮件 附加文件。

它工作得很好。 只需要指定base_url即可定义附件文件路径

控制器

$email_config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.gmail.com',
    'smtp_port' => 465,
    'smtp_user' => 'yourmail@gmail.com', // change it to yours
    'smtp_pass' => 'mypasswords', // change it to yours
    'mailtype'  => 'html',
    'charset'   => 'iso-8859-1'
);

// Defined Attachment file using variable
$atch=base_url().'html/images/logo.png';

$this->load->library('email', $email_config);

$this->email->set_newline("\r\n");
$this->email->from('test@gmail.com', 'Rudra');  // email From
$this->email->to('mailtosend@gmail.com');       // eMail to send
$this->email->subject('Mail with Attachment');  // Subject
$this->email->message("This is mail with Attachment file using CodeIgniter.");  // Message
$this->email->attach($atch);  // Attachment file defined using variable

$maill=$this->email->send(); // send mail

if($maill>0)
 {
  echo 'Email sent.';  // success
 }
 else
{
 show_error($this->email->print_debugger());
}

【讨论】:

  • 嗨,Rudra,我试过这段代码,但收到的是空邮件?当我删除此附件代码时,它工作正常,我还检查了我的文件路径。
  • 你能用配置文件分享你的控制器方法吗?我想你可能会错过配置它
  • 怎么分享我可以知道你的email id吗?
  • 你能分享你的电子邮件ID吗,我只是想告诉你代码正常工作,你会得到一个图片作为附件
  • 请检查您的邮件并在此处提供反馈
猜你喜欢
  • 2015-09-09
  • 2016-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多