1

I'm running into an error when trying to send an email using codeigniter. I've tested the function I'm using with an online server but it still throws the same error.

Below is my function:

//send email
    function sendEmail() {
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'ssl://smtp.googlemail.com',
            'smtp_port' => 465,
            'smtp_user' => 'email', // change it to yours
            'smtp_pass' => 'pswd', // change it to yours
            'mailtype' => 'html',
            'charset' => 'iso-8859-1',
            'wordwrap' => TRUE
        );

        $message = 'Test message';
        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");
        $this->email->from('zzz@gmail.com'); // change it to yours
        $this->email->to('xxx@gmail.com'); // change it to yours
        $this->email->subject('Resume from JobsBuddy for your Job posting');
        $this->email->message($message);
        if ($this->email->send()) {
            echo 'Email sent.';
        } else {
            show_error($this->email->print_debugger());
        }
    }

I'm getting the below error:

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 w84sm8590284ioi.20 - gsmtp Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

Kindly assist

AJ X.
  • 2,639
  • 1
  • 20
  • 32
Kabs
  • 227
  • 2
  • 4
  • 11

1 Answers1

0

The answer isn't code related but due to the fact that your Gmail account must be enabled to permit smtp/IMAP access. From the Google help Center:

  1. Sign in to the Gmail web interface.
  2. Open the 'Forwarding and POP/IMAP' tab on your 'Settings' page, and configure IMAP or POP.
  3. After enabling this in Gmail, make sure you click 'Save Changes' so Gmail can communicate with your mail client
AJ X.
  • 2,639
  • 1
  • 20
  • 32