Welcome Guest, Not a member yet? Register   Sign In
Email attachment not working
#1

[eluser]Computerzworld[/eluser]
I am using CI Email library for sending emails. But attachment is not working for me. I have tried to attach files using $this->email->attach() function. But it didn't worked.

Here is my function for sending email.
Code:
function send()
    {
        $subject = 'testing subject';
        //Message
        $message = 'testing';
        
        $from0 = '[email protected]';
        $from1 = 'Administrator';
        
        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'mydomain.com';
        $config['smtp_user'] = 'user';
        $config['smtp_pass'] = 'pass';
        $config['mailtype'] = 'html';
        
        $this->load->library('email',$config);
        
        $this->email->from($from0,$from1);
        $this->email->to('[email protected]');
        $this->email->cc('');
        $this->email->bcc('');

        $this->email->subject($subject);
        $this->email->message($message);
                    
        $path = "uploads/files/1.jpg";
                    
        $this->email->attach($path);
                    
            
        $this->email->send();
        echo $this->email->print_debugger();
    }
But I am getting an error like

Unable to open this attachment: uploads/files/1.jpg . I have tried with various paths like $_SERVER['DOCUMENT_ROOT'].'uploads/files/1.jpg' , './uploads/files/1.jpg' etc. But no one works for me. Even I have checked for permissions for upload folder. Its already set to rwx for all users. But still attachment doesn't works. Also when I try to send the mail with attachment mail body doesn't comes. As soon as I comment this line,the message body comes. I don't know what is the problem behind this. Please help me. Thanks in advance.
#2

[eluser]Zeeshan Rasool[/eluser]
Did you check like that?use '.' before upload/files

Code:
$path = ".uploads/files/1.jpg";
#3

[eluser]Thorpe Obazee[/eluser]
In case you upload the file before you send it, you can use the file upload, $this->upload->data() array.
#4

[eluser]Computerzworld[/eluser]
Yes. I have checked with .uploads too but it didn't work. Also I have that file already available on server so it doesn't need to be uploaded...




Theme © iAndrew 2016 - Forum software by © MyBB