PHP(Codeigniter) continues to send email even with wrong mail server data

Asked

Viewed 29 times

0

Therefore, in my login system I have a zone where the user asks to recover the password and is sent an email with the new password. When testing the code, I noticed that if I change the data from my email server, the email continues to be sent without giving any error.

Does anyone know why this is happening?

Code:

$servidoremail = file(APPPATH.'libraries/connections/servidoremail.txt',FILE_IGNORE_NEW_LINES);
      $sname= $servidoremail['0'];
      $suser= $servidoremail['1'];
      $spass= $servidoremail['2'];
      $sport= $servidoremail['3'];
      $email = addslashes($_POST['email']);
      $user = $this->Usuario_model->getuserbyemail($email);
      if(isset($user)){
        $novasenha =addslashes(substr(md5(time()), 0, 6));
        $this->Usuario_model->updatepass($novasenha,$email);
        $config['protocol'] = 'smtp';
        $config['mailpath']         = '/usr/sbin/sendmail';
        $config['smtp_host']        = $sname;
        $config['smtp_auth']        = true;  
        $config['smtp_user']        = $suser;
        $config['smtp_pass']        = $spass= $servidoremail['2'];
        $config['smtp_port']        = $sport;
        $config['smtp_auto_tls']    = true;
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->from('[email protected]');
        $this->email->to($email);
        $this->email->subject('Nova password');
        $this->email->message('Nova senha: '.$novasenha);

        if($this->email->send()){
          $data['resposta'] = 'Password alterada, verifique o seu email';
          $data['tipo'] = 'bg-success';
          $this->load->view('recuperarpassword',$data);

        }else{
          echo $this->email->print_debugger();
          //$data['resposta'] = 'Erro ao enviar email';
          //$data['tipo'] = 'bg-danger';
          //$this->load->view('recuperarpassword',$data);
        }
  • 1

    There is not much to identify because the function is incomplete. The array $config is being used in place of your code?

  • You’re right, I already reworked the text. Continue to send the email

1 answer

0


Okay, I solved the problem. I had created a config/email.php file where I had entered the data by direct code. When this file exists, it is not necessary to use "$this->email->initialize()" and even using it, it is ignored (I assume from the assumption given what was happening to me). https://codeigniter.com/user_guide/libraries/email.html

  • Mark the answer so the question doesn’t stay open.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.