在Codeigniter中将带附件的邮件发送到多个列表

时间:2016-09-22 04:15:23

标签: php codeigniter phpmailer

使用以下代码,它的工作正常。 $ maillist是我的成员与电子邮件列表。 现在问题,我运行这个。会员收到多个附件作为列表前进。

像我的第二个成员收到两个附件[相同的附件]第三个接收三个,依此类推。

您的帮助将非常感谢。 提前致谢 PRASHANT。

$path_to_the_file = "/data/mail-attachment/";
                $attachfile = $path_to_the_file.$mailinfo->attachment;

                //SET COMMON VARIABLES
                $fromname = "helpdesk@domainname.com";
                $subjectline = $mailinfo->subjectline;
                $this->load->library('email');
                $message = $mailinfo->mailbody;
                $message .= "<br /><br /><a href=\"$attachfile\">Download Attachment</a>";

                foreach ($maillist as $key => $value) 
                {
                    $emailto = $value->email;

                    $this->email->set_newline("\r\n");
                    $this->email->from($fromname);      // change it to yours
                    $this->email->to($emailto);         // change it to yours
                    $this->email->subject($subjectline);
                    $this->email->message($message);
                    $this->email->attach($attachfile);
                    $this->email->set_mailtype("html");

                    if($this->email->send()) { 
                        $success_mail_count++;
                    }       
                }

1 个答案:

答案 0 :(得分:0)

试试这个...... 您需要在邮件发送后传递clear(TRUE)以清除附件。

        path_to_the_file = "/data/mail-attachment/";
        $attachfile = $path_to_the_file . $mailinfo->attachment;

        //SET COMMON VARIABLES
        $fromname = "helpdesk@domainname.com";
        $subjectline = $mailinfo->subjectline;
        $this->load->library('email');
        $message = $mailinfo->mailbody;
        $message .= "<br /><br /><a href=\"$attachfile\">Download Attachment</a>";
        $emailto = array();
        foreach ($maillist as $key => $value) {
            $emailto = $value->email;
        }
        $this->email->set_newline("\r\n");
        $this->email->from($fromname);   // change it to yours
        $this->email->to($emailto);   // change it to yours
        $this->email->subject($subjectline);
        $this->email->message($message);
        $this->email->attach($attachfile);
        $this->email->set_mailtype("html");
        if ($this->email->send()) {
            $this->email->clear(TRUE);
            $success_mail_count++;
        }