send email to codigneter using SMTP GMAIL LOCALHOST

Asked

Viewed 3,510 times

3

I cannot send email, from the error message below. I am 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());
          }
        }
  • Welcome to Stackoverflow in English. Make a tour to learn how the site works.

  • Friend, use the Mandrill api. With it you can send emails via post request, so you don’t even need to set up the smtp on your server.

  • Follow this video. It shows step by step, is very explanatory. I did the same project a while ago using Apache and xammp.

2 answers

2

Google has gone on to reject sending emails using an unauthorized application.

If you take a look at your Gmail inbox, you will get a Google email stating that a login tactic has been blocked.

https://support.google.com/a/answer/176600?hl=pt-BR

From the link above:

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

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

$config['smtp_host'] = 'ssl://smtp.gmail.com';
  • remember that you will need to have access to the DNS settings to be able to point the Spf, the uploads of your localhost leave by your router or is the valid ip of it that needs to be set as ip allowed by google, if your ip is dynamic forget locust, for google vc is a SPAMMER

0

Friend, your gmail host settings are incorrect. Follow the correct setup, 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);

Browser other questions tagged

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