duankan8739 2017-03-16 12:34
浏览 31
已采纳

邮件不发送/删除php codeigniter

I am trying to send forgot password link to gmail. but can't get success.

Here is my little code. I have my config file here. If any changes needed then please suggest. I am using two gmail account to send mail from one gmail account to other gmail account.

Here is my config file 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']    = 'xyz@gmail.com',
        $config['smtp_pass']    = '123',
        $config['charset']    = 'utf-8',
        $config['newline']    = "
",
        $config['mailtype'] = 'text', // or html
        $config['validation'] = TRUE // bool whether to validate email or not 
    );

Here is my code for deliver mail.

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('xyz@gmail.com', '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');
                }
  • 写回答

2条回答 默认 最新

  • doukui4786 2017-03-16 12:45
    关注

    Nothing wrong in your code. Its might be because of google security. Try to allow access for 'Less secure apps' in google account settings after logging in to your account

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度