在CodeIgniter中发送带附件的电子邮件

时间:2018-05-23 05:58:32

标签: codeigniter email codeigniter-3 email-attachments

通过CodeIgniter Mysource代码中的电子邮件进行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替换路径。

1 个答案:

答案 0 :(得分:0)

您可以使用

发送附件

base_url

codeigniter中的

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

完美的工作。  您只需指定$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()); } 来定义附件文件路径

<强>控制器

#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s1 = "string1";

   reverse(s1.begin(),s1.end());

   cout << s1;
   return 0;
}
相关问题