Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么我在使用CI发送电子邮件时无法将电子邮件id传递到文件?_Php_Codeigniter - Fatal编程技术网

Php 为什么我在使用CI发送电子邮件时无法将电子邮件id传递到文件?

Php 为什么我在使用CI发送电子邮件时无法将电子邮件id传递到文件?,php,codeigniter,Php,Codeigniter,嗨,这是我的控制器功能。在我看来,我将一个来自数据库的电子邮件变量设置为会话数据。我在控制器中验证了它是否正确。我完全明白了。但当我试图将该电子邮件id发送到字段变量时,它不起作用 function do_upload() { $config['upload_path'] = 'C:\xampp\htdocs\upload\application'; $config['allowed_types'] = 'doc|docx|pdf'; $config['max_size

嗨,这是我的控制器功能。在我看来,我将一个来自数据库的电子邮件变量设置为会话数据。我在控制器中验证了它是否正确。我完全明白了。但当我试图将该电子邮件id发送到字段变量时,它不起作用

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


}

您的$电子邮件正在传递到函数,但不带引号。想一想这次会议的结果如何。如果会话中的电子邮件是xxx@gmail.com那么你通过了以下考试:

$this->email->to(xxx@gmail.com); 
你想让那一行读成:

$this->email->to('xxx@gmail.com'); 
试试这个:

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

show_error()
告诉您什么?您没有选择要上载的文件…………根据代码,只有在上载成功时才会发送电子邮件。从外观上看,文件上载没有发生,因此电子邮件脚本没有运行。您的错误是“您没有选择要上载的文件”,但您认为问题在于设置“到”字段?怎么用?为什么?是的,我调试的时候完全正确,当我保持xxx@gmail.com代替$email归档,它正在工作,email正在工作