Php 如何在CodeIgniterRESTController中从RESTAPI发送邮件?

Php 如何在CodeIgniterRESTController中从RESTAPI发送邮件?,php,rest,codeigniter,api,email,Php,Rest,Codeigniter,Api,Email,我在CodeIgniter中使用RESTAPI,并试图从我的REST控制器发送电子邮件。这就是我尝试过的: public function registration_post(){ $jsonArray = json_decode(file_get_contents('php://input'),true); $user_name = $jsonArray['user_name']; $email = $jsonArray['email']; $password = $json

我在CodeIgniter中使用RESTAPI,并试图从我的REST控制器发送电子邮件。这就是我尝试过的:

public function registration_post(){

  $jsonArray = json_decode(file_get_contents('php://input'),true);
  $user_name = $jsonArray['user_name'];
  $email = $jsonArray['email'];
  $password = $jsonArray['password'];

    $result = $this->reg_model->insert_api($user_name,$email,$password);
        if ($result){
            $this->load->library('email');
            $from_email = "abc@gmail.com"; 
            $this->email->from($from_email, 'Name'); 
            $this->email->to($email);
            $this->email->subject('email subject');
            $message = 'email body';                 
            $this->email->message($message);
            $this->email->send();
            $data = $this->response($this->reg_model->get($user_name));
        }
} 
这是一个POST请求API,我通过POST调用成功地将用户数据插入数据库,然后发送电子邮件。但是,电子邮件没有发送


insert_api()函数将数据插入数据库,我也从get()函数获得响应。

编辑本地主机中通过gmail发送电子邮件的设置

public function registration_post(){

$jsonArray = json_decode(file_get_contents('php://input'),true);
$user_name = $jsonArray['user_name'];
$email = $jsonArray['email'];
$password = $jsonArray['password'];

$result = $this->reg_model->insert_api($user_name,$email,$password);
    if ($result){
        $config = Array(        
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_port' => 465,
            'smtp_user' => 'YOURGMAIL',
            'smtp_pass' => 'YOURGMAILPASSWORD',
            'smtp_timeout' => '4',
            'mailtype'  => 'html', 
            'charset'   => 'iso-8859-1'
        );
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n"); 
        $from_email = "abc@gmail.com"; 
        $this->email->from($from_email, 'Name'); 
        $this->email->to($email);
        $this->email->subject('email subject');
        $message = 'email body';                 
        $this->email->message($message);
        $this->email->send();
        $data = $this->response($this->reg_model->get($user_name));
    }
} 

设置正确。我如何知道我的smtp_主机?我不明白protocol=>sendmail是什么意思?我已经更新了答案。浏览一下,您将获得Protocoleded的详细信息。刚才,我的本地主机中正在运行一个电子邮件配置。