为什么我在使用CI发送电子邮件时无法将电子邮件ID传递到TO字段?

时间:2012-11-01 05:57:36

标签: php codeigniter

嗨这是我的控制器功能。在我看来,我将一个来自数据库的电子邮件变量设置为会话数据。我在控制器中验证了它是否正确无误。我完美地完成了它。但是,当我尝试将该电子邮件ID作为TO字段变量发送时,它无效。

function do_upload()
{ 
    $config['upload_path'] = 'C:\xampp\htdocs\upload\application';
    $config['allowed_types'] = 'doc|docx|pdf';
    $config['max_size'] = '10240';
    $email = $this->session->userdata("employer_email");// If i echo $email; I will get my passed session variable

    $this->load->library('upload', $config);

    if ( ! $this->upload->do_upload())
    {   
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    { 
        $data = array('upload_data' => $this->upload->data()); 

        echo "Resume Successfully uploaded to database.............";
        $file = $data['upload_data']['full_path'];

    $config = Array(
      'protocol' => 'smtp',
      'smtp_host' => 'ssl://smtp.googlemail.com',
      'smtp_port' => 465,
      'smtp_user' => 'xxx@gmail.com', // change it to yours
      'smtp_pass' => 'xxxx', // change it to yours
      'mailtype' => 'html',
      'charset' => 'iso-8859-1',
      'wordwrap' => TRUE
    );


      $this->load->library('email', $config);
      $this->email->set_newline("\r\n");
      $this->email->from('xxx@gmail.com'); // change it to yours
      $this->email->to($email); // But here it's not working
      $this->email->subject('Email using Gmail.');
      $this->email->message('Working fine ! !');
      $this->email->attach($file);
      if($this->email->send())
     {
      echo 'Email sent.';
     }
     else
    {
     show_error($this->email->print_debugger());
    }
    }


}

1 个答案:

答案 0 :(得分:1)

您的$ email正在传递给没有引号的函数。想想它将如何来自会议。如果会话中的电子邮件是xxx@gmail.com,那么您将传递以下内容:

$this->email->to(xxx@gmail.com); 

您希望该行读取:

$this->email->to('xxx@gmail.com'); 

试试这个:

$email = '"'.$this->session->userdata("employer_email").'"';