2019-02-14 10:10
浏览 132


I am trying to implement forgot password functionality into codeigniter but I face some issue like this someone, please help me to solve this. Also when I change the protocol to mail than it's give me one another error that,

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

Complete error is as below.

A PHP Error was encountered

    Severity: Warning

    Message: fsockopen(): unable to connect to ssl:// (Connection timed out)

    Filename: libraries/Email.php

    Line Number: 2069

    The following SMTP error was encountered: 110 Connection timed out
    Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

    Date: Thu, 14 Feb 2019 10:52:06 +0100
    From: "arazu" <>
    Return-Path: <>
    Subject: =?UTF-8?Q?Reset=20your=20passwrod?=
    Reply-To: <>
    User-Agent: CodeIgniter
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <>
    Mime-Version: 1.0

    Content-Type: multipart/alternative; boundary="B_ALT_5c653a46009c6"

    This is a multi-part message in MIME format.
    Your email application may not support this format.

    Content-Type: text/plain; charset=UTF-8
    Content-Transfer-Encoding: 8bit

    Click Here if you want to reset your password

    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable

    =3Ca href=3D'
    5acc175d4c1847fab1f2ee'=3EClick Here=3C/a=3E if you want to reset your pass=


My forgot_password() code part is as follows.

public function forgot_password(){
        if($this->form_validation->run() == FALSE){
            echo "please enter email";
            $email = $this->input->post('email');
            $result = $this->registration_model->email_exists($email);
            if($result == TRUE){
                $email_config = array(
                    'charset'   => 'utf-8',

                $this->email->subject('Reset your passwrod');

                $message = "this email is sent you to reset your password";
                $message = "<a href='".base_url()."login/reset_password/$temp_pass'>Click Here</a> if you want to reset your password";

                    echo "hello"; exit();
                        echo 'check your for instruction, thank you';
                    //echo "email is not sent, please contact your administrator";
                     echo $this->email->print_debugger();
                echo "your email is not exists into database";


How I send email in Codeigniter on localhost?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzongmu2543
    douzongmu2543 2019-02-14 18:18

    @Arazu Gajera

    Emails can be sent when it's the live server.

    BUT if you want to set email working facility in localhost, then you have to set SMTP configuration as below.

    NOTE:- This is just basic setup for SMTP configuration. Different Email libraries may have different syntax.

    //Load email Library
    $email_config ['charset']       = 'utf-8';
    $email_config ['mailtype']      = 'html';
    $email_config ['newline']       = "
      //SMTP configuration
      $email_config = array(
                    'protocol' =>'smtp',

    so, $email_config ['charset'] = 'utf-8';, $email_config ['mailtype'] = 'html';, $email_config ['newline'] = " "; are COMMON email config variables used in both localhost and Live-server.

    And when it's localhost, email functionality will use //SMTP configuration $email_config array.

    NOTE :- Please keep in mind that when your website is going on LIVE Server, It's advisable to remove this if($_SERVER['HTTP_HOST']=="localhost") email condition from all files wherever you have used it.

    EDIT :- (IMPORTANT) Please change below line

    ");  //Use double quotes for 

    Because only means new line if it is in double quotes. In single quotes it means the literal characters .

    点赞 评论
  • dounie5475
    dounie5475 2019-02-16 04:41

    Please load email library before:


    点赞 评论