【问题标题】:Unable to send mail with attachment using codeigniter无法使用 codeigniter 发送带附件的邮件
【发布时间】:2013-11-18 10:18:36
【问题描述】:

我正在尝试发送带有附件的邮件,但屡次失败。但是没有附件可以发送邮件。下面是我的函数。

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";

                }


            }

我哪里出错了?

【问题讨论】:

    标签: php codeigniter email


    【解决方案1】:

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

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

    最好通过文件上传你要发送的文件后,从上传的数据中获取文件的完整路径并给出$file

    【讨论】:

    • 我试过了,即使这样也会出现这样的错误。遇到 PHP 错误严重性:通知消息:未定义索引:主题文件名:libraries/Email.php 行号:982
    • 只做这个 echo $this->email->print_debugger();告诉我们你得到了什么
    • 添加了 print _debugger。但输出什么也没显示。文件名和路径名也正确,我也检查了上传文件夹和文件名。
    • 不只是用完整路径回显文件名并将其粘贴到浏览器中。
    • 我收到了这个错误。无法使用 PHP mail() 发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。用户代理:CodeIgniter 日期:2013 年 11 月 18 日星期一 03:57:56 -0700 来自:“Gowtham”
      返回路径:
      回复:“hr@virtutechsolutions .com"
      X-Sender: hr@virtutechsolutions.com X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: Mime-Version: 1.0 Content-类型:多部分/混合;边界="B_ATC_5289f2b43974f" =?iso-8859-1?Q?Test_Email?=
    【解决方案2】:

    执行以下操作..

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

    希望这会有所帮助。

    【讨论】:

    • 我听从了你的建议,邮件已发送但没有附件。:(
    【解决方案3】:

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

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

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

    C:/xampp/htdocs/mail
    

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 1970-01-01
      • 2017-10-08
      • 2017-02-03
      • 1970-01-01
      • 2018-08-04
      • 2015-01-18
      • 2017-06-11
      • 1970-01-01
      相关资源
      最近更新 更多