在codeigniter中发送带有多个附件的电子邮件时出错



代码正在工作,但无法发送许多文件。。。。只能发送图像

控制器

    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'   => 'rn'
                );
            $this->load->library('email',$config);
            $this->email->set_newline('rn');
            $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;
    }

发送docx、pptx的多个附件时出错
220-gator3150.hostgator.com ESMTP Exim 4.85#2 2015年11月19日星期四00:10:43-0600 220我们不授权使用此系统传输未经请求的220和/或批量电子邮件。

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

对于多个附件,您可以多次使用同一函数,在您的代码中,您没有多次使用,也没有给出循环。

尝试使用完整路径,而不仅仅是url-

 $this->email->attach('C:UsersxyzDesktopimagesabc.png');

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

也可以尝试将字符集更改为-

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

Codeigniter发送带有附加文件的电子邮件

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

相关内容

  • 没有找到相关文章

最新更新