title: here using ajax i am click the forget button and sending mail to particular email using codeigniter
body: <p><strong>here using ajax i am click the forget button and sending mail to particular email ,but i am getting the error Fail what is the problem i am not getting please any one help me below i shown form and controller</strong>  </p>
  
  <p><strong>Form</strong></p>
  
  <pre><code>&lt;div class="field-wrap"&gt;
      &lt;label class="view-label"&gt;Email Address&lt;/label&gt;
      &lt;input type="email" placeholder="Email Address" name="email" id="email" class="input-control inputstyle" value="&lt;?php echo set_value('email'); ?&gt;"/&gt;
      &lt;span class="text-danger"&gt;&lt;?php echo form_error('email'); ?&gt;&lt;/span&gt;
  &lt;/div&gt;
  &lt;!--&lt;div id='errorDiv' class='col-xs-12 pull-right'&gt; &lt;/div&gt;--&gt;
  &lt;div class="field-wrap"&gt;
      &lt;input type="password" placeholder="Password" class="inputstyle" name="password" id="password" value="&lt;?php echo set_value('password'); ?&gt;"/&gt;
      &lt;span class="text-danger"&gt;&lt;?php echo form_error('password'); ?&gt;&lt;/span&gt;
  
      &lt;a href="javascript:void(0)" class="btn btn-link btn-nobg" id="btn-show-forgot" &gt;Forgot ?&lt;/a&gt;  
  
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>javascript</strong></p>
  
  <pre><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  
  &lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          $("#btn-show-forgot").click(function () {
              //e.preventDefault();
              var email = $("#email").val();
              //  var password= $("#password").val();
  
  
              $.ajax({
                  type: "POST",
                  url: "&lt;?php echo base_url() ?&gt;" + "index.php/Login_cntrl/sendmail",
                  data: {email: email},
                  success: function (data)
                  {
                      alert('Successfully send a mail');
                  },
                  error: function ()
                  {
                      alert('fail');
                  }
              });
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public function sendmail() {
  
  
          $this-&gt;form_validation-&gt;set_rules('email', 'Email or number', 'required|min_length[10]|max_length[30]');
          if ($this-&gt;form_validation-&gt;run() == FALSE) {
              $this-&gt;load-&gt;view('login');
          } else {
  
              $data['email'] = $this-&gt;input-&gt;post('email');
  
              $findemaill = $this-&gt;Login_model-&gt;getUserInfoByEmail($data['email']);
  
  
  
              if (!empty($findemaill)) {
                 // $this-&gt;Login_model-&gt;getUserInfo('$id');
                 // $this-&gt;session-&gt;set_userdata('forgot_password_flag', 'yes');
                  $emailTo = $this-&gt;input-&gt;post('email');
                     $this-&gt;session-&gt;set_userdata('findemaill',  $emailTo);
                    //  $this-&gt;session-&gt;userdata('findemaill');
  
                  $data['result'] = $this-&gt;Login_model-&gt;forgot_pass_retrive($emailTo);
                  $id = $data['result']-&gt;id;
                  $this-&gt;session-&gt;set_userdata('idd', $id);
  
  
  
                  $six_digit_random_number = mt_rand(100000, 999999);
  
                  $this-&gt;session-&gt;set_userdata('otp', $six_digit_random_number);
  
                  $this-&gt;load-&gt;model('Login_model');
  
                  $pass['pass'] = $this-&gt;Login_model-&gt;forgot_pass_retrive($emailTo);
  
                  $config['protocol'] = 'smtp';
  
                  $config['smtp_host'] = 'ssl://smtp.gmail.com';
  
                  $config['smtp_port'] = '465';
  
                  $config['smtp_timeout'] = '7';
  
                  $config['smtp_user'] = 'tworkreport@gmail.com';
  
                  $config['smtp_pass'] = '8722248936';
  
                  $config['charset'] = 'utf-8';
  
                  $config['newline'] = "\r\n";
  
                  $config['mailtype'] = 'html'; // or html
  
                  $config['validation'] = TRUE; // bool whether to validate email or not      
  
                  $this-&gt;email-&gt;initialize($config);
                  $this-&gt;email-&gt;from('tworkreport@gmail.com', 'Terasukhintrade');
                  $this-&gt;email-&gt;to($emailTo);
  
  
                  $this-&gt;email-&gt;subject('Reset your password');
  
                  $body=$this-&gt;load-&gt;view('forgotmailer',$data,TRUE);
  
                  $this-&gt;email-&gt;message('Use the following OTP to reset password '.$body );
  
                  $this-&gt;email-&gt;send();
  
                  echo $this-&gt;email-&gt;print_debugger();
  
                  $this-&gt;load-&gt;view('login',$data);
              } else {
  
                  $this-&gt;session-&gt;set_flashdata('message', ' Email address not found!');
                  $this-&gt;load-&gt;view('login',$data);
              }
  
          }
      }
  </code></pre>