无法使用codeigniter发送带附件的邮件

时间:2013-11-18 10:18:36

标签: php codeigniter email

我正在尝试发送带附件的邮件,但反复失败。但是没有附件能够发送邮件。以下是我的功能。

public function sendmail($jid,$eid)
        {           
            $empdata = $this->search_m->eid($eid);
            $user = $this->session->userdata('userid');
            $jsdata = $this->search_m->jid($user);

            foreach($empdata->result() as $rows)
            {
                $empmail = $rows->email;                
            }


            foreach($jsdata->result() as $row)
            {
                $jsres = $row->resume;          
            }


             $file = "uploads/".$jsres;



            $this->load->library('email');
            //$this->email->clear();
            $config['charset'] = 'iso-8859-1';
            $config['wordwrap'] = TRUE; 

            $config['protocol'] = 'mail';
            $config['mailpath'] = '/usr/sbin/sendmail';     
            $config['smtp_port']=587;
            $config['smtp_host'] = 'smtp.gmail.com';
            $config['smtp_user'] = 'mail@gmail.com';
            $config['smtp_pass'] = 'password';
            $config['validate'] = TRUE;
            $this->email->initialize($config);          

            $this->email->from( 'hr@virtu.com','Gowtham');
            $this->email->to('gorodda@gmail.com');          
            $this->email->subject('Testing Email');
            $this->email->message('I applied to ur job');
            $this->email->attach($file);
            $this->email->send();

            if(!$this->email->send())
                {
                    echo " mail not send";

                }


            }

我哪里错了?

3 个答案:

答案 0 :(得分:0)

$file将是上传文件的完整路径,如

$file = site_url()."uploads/".$jsres;

在上传要通过文件发送的文件后,最好从上传的数据中获取文件的完整路径,并将其作为$file

答案 1 :(得分:0)

执行以下操作..

 $path = set_realpath('uploads/');
 $this->email->attach($path . $jsres);

希望这有帮助。

答案 2 :(得分:0)

您可以使用以下方式添加完整链接:

$file=$_SERVER['DOCUMENT_ROOT']."/uploads/".$jsres;

$_SERVER['DOCUMENT_ROOT']将获取您的本地主机地址,如:

C:/xampp/htdocs/mail
相关问题