0

Code is working but can't send many files.... only images can be sended

controller

    public function sende(){
            $from = $_POST['from'];
            $address = $_POST['address'];
            $to_name = $_POST['to_name'];
            $to_email = $_POST['to_email'];
            $cc = $_POST['cc'];
            $subject = $_POST['subject'];
            $mesg = $_POST['mesg'];
            $start = $_POST['start'];
            $end = $_POST['end'];
            $mid1 = $_POST['mid1'];
            $mid2 = $_POST['mid2'];
            $message = $start.$mid1.$mesg.$mid2.$end;
            $config = array(
                    'useragent' => 'CodeIgniter',
                    'protocol'  => 'smtp',
                    'smtp_host' => 'ssl://smtp.googlemail.com',
                    'smtp_port' => '465',
                    'smtp_user' => '***',
                    'smtp_pass' => '**',
                    'mailtype'  => 'html',
                    'charset'   => 'utf-8',
                    'newline'   => '\r\n'
                );

            $this->load->library('email',$config);
            $this->email->set_newline('\r\n');
            $this->email->from($address,$from);
            $this->email->to($to_email);
            $this->email->subject($subject);
            $this->email->message($message);
            $this->email->cc($cc);
            $path = $this->config->item('server_root');
            $file = $path.'/mshaadi/';
            $this->load->library('upload');
            $m = count($_FILES['atta']['name']);
            $files = $_FILES;
            for($i=0; $i< $m; $i++){
                $_FILES['atta']['name']= $files['atta']['name'][$i];
                $_FILES['atta']['type']= $files['atta']['type'][$i];
                $_FILES['atta']['tmp_name']= $files['atta']['tmp_name'][$i];
                $_FILES['atta']['error']= $files['atta']['error'][$i];
                $_FILES['atta']['size']= $files['atta']['size'][$i];
                $this->upload->initialize($this->set_upload_options());
                $this->upload->do_upload('atta');
                $a = $files['atta']['name'][$i];
                $mm = base_url().'images/'.$a;
                $this->email->attach($mm);
            }
            if($this->email->send()){
                redirect('Email');
            }else{
                show_error($this->email->print_debugger());
            }
}
private function set_upload_options(){
        $config = array();
        $config['upload_path'] = './images/';
        $config['allowed_types'] = 'gif|jpg|png|pdf|sql|docx|pptx';
        $config['max_size']      = '10000';
        $config['overwrite']     = TRUE;
        return $config;
    }

Error while sending multiple attachment of docx, pptx
220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.

220-gator3150.hostgator.com ESMTP Exim 4.85 #2 Thu, 19 Nov 2015 00:10:43 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. 

hello: 250-gator3150.hostgator.com Hello 127.0.0.1 [112.196.141.163]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
from: 250 OK
to: 501 <>: missing or malformed local part
The following SMTP error was encountered: 501 <>: missing or malformed local part 
data: 503-All RCPT commands were rejected with this error:
503-501 <>: missing or malformed local part
503 Valid RCPT command must precede DATA
The following SMTP error was encountered: 503-All RCPT commands were rejected with this error: 503-501 <>: missing or malformed local part 503 Valid RCPT command must precede DATA 
500 unrecognized command 
The following SMTP error was encountered: 500 unrecognized command 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Thu, 19 Nov 2015 07:10:37 +0100
From: "" <>
Return-Path: <>
Subject: =?ISO-8859-1?Q??=
Reply-To: "" <>
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <564d67dddeddc>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_564d67dddeddc"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_564d67dddeddc
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit




--B_ALT_564d67dddeddc
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable



--B_ALT_564d67dddeddc--
Sachin Marwha
  • 137
  • 1
  • 3
  • 11

2 Answers2

0

For multiple attachments you can use the same function multiple times,On your code you haven't used multiple times and not given loop too.

Try using the full path instead of just the url-

 $this->email->attach('C:\Users\xyz\Desktop\images\abc.png');

or

$attched_file= $_SERVER["DOCUMENT_ROOT"]."/uploads/".$file_name;
$this->email->attach($attched_file);

also try changing the charset as-

$config['charset'] = 'iso-8859-1';

Codeigniter send email with attach file

https://ellislab.com/codeigniter/user-guide/libraries/email.html

Community
  • 1
  • 1
Sanjuktha
  • 1,065
  • 3
  • 13
  • 26
0
$this->load->library('email');
$this->load->helper('path');
$this->load->helper('directory'); 

//setting path to attach files 
$path = set_realpath('assets/your_folder/');
$file_names = directory_map($path);

    $this->email->clear(TRUE);
    $this->email->to($address);
    $this->email->from('your@example.com');
    $this->email->subject('Here is your info '.$name);
    $this->email->message('Hi  Here is the info you requested.'); 

    foreach($file_names as $file_name)
    {

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

    }

    $this->email->send();
Mitul
  • 3,431
  • 2
  • 22
  • 35