Gmail prevented sign in when using Codeigniter email library

Hi I have been trying to send an email using the codeigniter email library. I have the following code:

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

        $config['protocol']    = 'smtp';

        $config['smtp_host']    = 'ssl://smtp.gmail.com';

        $config['smtp_port']    = '465';

        $config['smtp_timeout'] = '7';

        $config['smtp_user']    = 'myemail@gmail.com';

        $config['smtp_pass']    = 'mypassword';

        $config['charset']    = 'utf-8';

        $config['newline']    = "\r\n";

        $config['mailtype'] = 'text'; // or html

        $config['validation'] = TRUE; // bool whether to validate email or not      

        $this->email->initialize($config);


        $this->email->from('harolddecapia@gmail.com', 'Harold Decapia');
        $this->email->to('harolddecapia@yahoo.com'); 


        $this->email->subject('Email Test');

        $this->email->message('Testing the email class.');  

        $this->email->send();

        echo $this->email->print_debugger();

When I run it, it returns the following:

> 220 smtp.gmail.com ESMTP ks5sm27098152wjb.13 - gsmtp 
hello: 250-smtp.gmail.com at your service, [180.191.89.193]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 ks5sm27098152wjb.13 - gsmtp 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Wed, 16 Mar 2016 06:22:40 +0100
From: "Harold Decapia" <harolddecapia@gmail.com>
Return-Path: <harolddecapia@gmail.com>
To: harolddecapia@yahoo.com
Subject: =?utf-8?Q?=45=6D=61=69=6C=20=54=65=73=74?=
Reply-To: "harolddecapia@gmail.com" <harolddecapia@gmail.com>
X-Sender: harolddecapia@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <56e8eda082584@gmail.com>
Mime-Version: 1.0
> 
> 
> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding:
> 8bit
> 
> Testing the email class.

I would like to emphasize on the error saying "Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14" since whenever I open the email address Im sending the email to, Im receiving a message from gmail saying that it prevented a sign in attempt which I think was me running and using the code to sign in and send the email. I really don't know what's the problem here. Does anyone know how to resolve this? All I want is to be able to send the email using CI's library. Thank you for those who'll answer.

Answers


Try going to https://accounts.google.com/DisplayUnlockCaptcha and click continue; then try sending the email again. This answer was derived from here


Need Your Help

How to render Emojis natively in Chrome?

html google-chrome emoji

I'm building a Meteor application that pulls Tweets and Instagram photos, stores relevant data from them into MongoDB, and then renders them out from the database onto the frontend.