在 CodeIgniter 中发送带附件的电子邮件
send email with attachment in CodeIgniter
通过电子邮件发送 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 替换了路径。
您可以使用
发送附件
$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());
}
通过电子邮件发送 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 替换了路径。
您可以使用
发送附件$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());
}