我正在使用PHPMailer和codeigniter
https://github.com/ivantcholakov/codeigniter-phpmailer发送附带附件的邮件,但我收到错误,我的代码是
$this->load->library('email');
$result = $this->email
->from('xxxx@gmail.com',"xxx xxx")
->reply_to('xxx@xxx.com') // Optional, an account where a human being reads.
->to('xxx@xxx.com')
->subject($subject)
->message($body)
->AddAttachment('/var/www/html/phase2.png', 'test.png')
->send();
致命错误:调用未定义的方法MY_Email :: AddAttachment()
答案 0 :(得分:1)
在 Codeigniter中,我们使用
attach()
代替AddAttachment()
。你附加的文件将它放在Codeigniter项目文件夹中。(外部应用程序文件夹)。
试试这个
$this->email->from('xxxx@gmail.com',"xxx xxx");
$this->email->reply_to('xxx@xxx.com');
$this->email->to('xxx@xxx.com');
$this->email->subject($subject);
$this->email->message($body);
$this->email->attach('assets/mail/phase2.png');
if(!$this->email->send()){
echo $this->email->print_debugger();
}
else{
echo "Success";
}
所以你的文件结构看起来像
application
assets
- images
- css
- js
- mail
- phase2.png
system
index.php
.htaccess
阅读此链接
答案 1 :(得分:0)
在github上我发现附加文件所需的方法不是AddAttachment,而是附加。
https://github.com/ivantcholakov/codeigniter-phpmailer/blob/master/libraries/MY_Email.php#L416
希望这有帮助!
答案 2 :(得分:0)
尝试像这样使用$_SERVER['DOCUMENT_ROOT']
:
$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/beta/uploads/file.pdf");