Rauf
Rauf

Reputation: 1

Codeigniter attachment not send along with email.

I am new to codeigniter. I am using CI 2.1.4 I am trying to attach a txt file with the email. The email go through and received in the email but without attachment.

Here is the code:

<?php
class email extends CI_Controller{
    function index(){
        $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.googlemail.com',
            'smtp_port'=>465,
            'smtp_user'=>'xxxxxx',
            'smtp_pass'=>'xxxxxx'
        );

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

        $this->email->set_newline("\r\n");
        $this->email->to('[email protected]');
        $this->email->from('xxxxxx', 'xxxxx');
        $this->email->subject('This is email subject');
        $this->email->message('This is email message body');

        $this->email->attach('attachments/file.txt');

            if($this->email->send()){
                echo("Email successfully send");
            } else{
                $this->email->print_debugger();
            } 
    }
}

?>

file.txt is the file placed i the attachments folder and attachment folder is at root directory.

URL,HTML helper is loaded in autoload.php.

any help ???

Upvotes: 0

Views: 1802

Answers (4)

Eranga Premathilaka
Eranga Premathilaka

Reputation: 125

I had the same problem and fixed it like below,

$this->email->attach(FCPATH. '\dist\pdf\\' . $filename);

In my case "/" didn't work. FCPATH is to get the absolute path which is a must. hope this will help.

Upvotes: 1

Raja Ram T
Raja Ram T

Reputation: 864

attachment folder should be in the same location of application folder

like Project Name | | -Application - your uploading folder

   $file =  './attachments/Info.txt';

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

Upvotes: 0

Dexter
Dexter

Reputation: 1796

try like this it should be problem of your path

$path = <?php base_url(); ?>.'attachments/file.txt';
$this->email->attach($path);

Upvotes: 1

kevindeleon
kevindeleon

Reputation: 1924

Makes sure you are using a file path for your attachment and not a URL.

/path/to/file/on/server/file.txt

Upvotes: 0

Related Questions