邮件不发送/删除php codeigniter

问题描述:

我想发送忘记密码链接到Gmail。但无法取得成功。邮件不发送/删除php codeigniter

这是我的小代码。我在这里有我的配置文件。如果需要更改,请提出建议。我使用两个Gmail帐户将邮件从一个Gmail帐户发送到其他Gmail帐户。

这里是我的配置文件email.php

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 
$config = Array(
     $config['protocol'] = 'smtp', 
     $config['smtp_host'] = 'ssl://smtp.gmail.com', 
     $config['smtp_port'] = '465', 
     $config['smtp_timeout'] = '7', 
     $config['smtp_user'] = '[email protected]', 
     $config['smtp_pass'] = '123', 
     $config['charset'] = 'utf-8', 
     $config['newline'] = "\r\n", 
     $config['mailtype'] = 'text', // or html 
     $config['validation'] = TRUE // bool whether to validate email or not 
    ); 

这里是我的邮件传递代码。

if($this->form_validation->run()) 
      { 
       //echo 1; 
       //echo validation_errors(); 
       $this->load->library('email'); 
       $reset_key = md5(uniqid());    
       $this->load->model('User_Model'); 
       if($this->User_Model->update_reset_key($reset_key)) 
       {     

        $this->email->from('[email protected]', 'data-+-'); 
        $this->email->to($this->input->post('email')); 
        $this->email->subject('Reset you account password at Mahesh Makwana'); 
        $message = "<p><h4>You or someone request to reset your password.</h4></p>"; 
        $message.="<a href='".base_url(). "reset_password/".$reset_key."'>Click here to reset your password</a>"; 
        $this->email->message($message); 
         if($this->email->send()) 
         { 
          echo 'Kindly check your email '.$this->input->post('email').' to reset your password'; 
         } 
         else 
         { 
          echo 'Cannot send email! Kindly contact to our customer service to help you.!'; 
         } 
        } 
        else{ 
         echo 1; 
        } 
       } 
       else 
       { 
        //echo 0; 
        //echo validation_errors(); 
        $this->load->view('include/forgetpassword'); 
       } 

代码没有错。这可能是因为谷歌的安全。尝试允许在谷歌帐户设置“安全性较低的应用程序的访问登录到您的帐户后

https://www.google.com/settings/security/lesssecureapps

+0

我认为你是正确的,因为当我尝试发送邮件,谷歌邮件我与**审核被阻止的登录尝试**。 – Mahi

+0

邮件收件人(收件人)是否有此功能来接收邮件。 – Mahi

+0

只有邮件发件人帐号应该允许应用程序 –

管理您的配置设置,如下图所示:

 $config['protocol'] = 'smtp'; 
     $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
     $config['smtp_port'] = '465'; 
     $config['smtp_timeout'] = '7'; 
     $config['smtp_user'] = '[email protected]'; 
     $config['smtp_pass'] = 'xxxxx'; 
     $config['charset'] = 'utf-8'; 
     $config['newline'] = "\r\n"; 
     $config['mailtype'] = 'text' // or html 
     $config['validation'] = TRUE; // bool whether to validate email or not 

然后加载email库集配置后使用$this->email->initialize($config);

$this->load->library('email'); 
$this->email->initialize($config); 
+0

您可以在不加载'$ this-> load-> library('email');'library的情况下编写代码。但它发送我的邮件垃圾邮件。你们俩**和** Kuldeep singh **都是对的。但我只能接受一个答案。 – Mahi