send email in codigneter using SMTP GMAIL LOCALHOST

3

I can not send email, giving the error message below. I'm using xampp, via localhost.

ello: 
The following SMTP error was encountered: 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Sun, 24 Apr 2016 10:01:58 -0300
From: "Meu" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Subject: assunto de e-mail
Reply-To: "[email protected]" <[email protected]>
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
function enviar_mensagem(){
          $mensagem = "Nome:".$this->input->post('txt_nome').br();
          $mensagem .= "E-mail:".$this->input->post('txt_email').br();
          $mensagem .= "Menagem:".$this->input->post('txt_mensagem').br();

            $config['smtp_host'] = 'smtp.gmail.com';
            $config['smtp_port'] = '465';
            $config['smtp_user'] = '[email protected]';
            $config['smtp_pass'] = 'XXXXXXX';
            $config['protocol'] = 'smtp';
            $config['validate'] = TRUE;
            $config['mailtype'] = 'html';
            $config['charset'] = 'utf-8';
            $config['newline'] = "\r\n";


          $this->load->library('email', $config);

          $this->email->from('[email protected]', 'Meu');
          $this->email->to('[email protected]');
          $this->email->subject('assunto de e-mail');
          $this->email->message($mensagem);
          if ($this->email->send()) {
              $this->load->view('sucesso_envia_contato');
          }
          else {
              print_r($this->email->print_debugger());
          }
        }
    
asked by anonymous 24.04.2016 / 15:34

2 answers

1

Google has turned away from sending emails using an unauthorized application.

If you take a look at your Gmail inbox, you will have an email from Google stating that a login attempt has been prevented.

link

From the link above:

  

"You need to set up an SPF record for the domain with the address   IP address of the device or application, to ensure that   recipients do not reject emails sent by that address.   You must also add this IP address to the Email List box   authorized in the Google Admin Console. For example, if the address of the   shipping device is 123.45.67.89, add this address to the   SPF record without removing Google Apps email servers from   register: v = spf1 ip4: 123.45.67.89 include: _spf.google.com ~ all "

UPDATE: You can even use your gmail for sending, but you can not use your own domain as an email from FROM, so you need to enable the use of less secure applications in this link and change your code:

$config['smtp_host'] = 'ssl://smtp.gmail.com';
    
24.04.2016 / 16:17
0

Friend, your gmail host configuration is incorrect. Here's the correct setting, try this one.

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
    
24.04.2016 / 16:06