1

I am using PHPMailer and codeigniter

https://github.com/ivantcholakov/codeigniter-phpmailer to send mail with attach file but I got error my code is

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

Fatal error: Call to undefined method MY_Email::AddAttachment()

tereško
  • 58,060
  • 25
  • 98
  • 150
Vipin Sharma
  • 421
  • 5
  • 24

3 Answers3

1

In Codeigniter we use attach() instead of AddAttachment(). And what ever the file you attaching place it inside Codeigniter project folder.(outside application folder).

Try this

$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";
}

So your file structure looks like

application
assets
    - images
    - css
    - js
    - mail
        - phase2.png
system
index.php
.htaccess

Read this links

  1. attach($filename[, $disposition = ''[, $newname = NULL[, $mime = '']]])
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
0

On github I found that the method needed to attach a file is not AddAttachment, but attach.

https://github.com/ivantcholakov/codeigniter-phpmailer/blob/master/libraries/MY_Email.php#L416

Hope this helps!

0

try using $_SERVER['DOCUMENT_ROOT'] like:

$mail->AddAttachment($_SERVER['DOCUMENT_ROOT']."/beta/uploads/file.pdf"); 
JuliaJ
  • 79
  • 7