1
votes

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('[email protected]'); // change it to yours
        $this->email->to('[email protected]'); // 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

1
Did you change this both ?? 'smtp_user' => 'email', 'smtp_pass' => 'pswd', - Abdulla Nilam
It's exactly what it says. You need to edit your Google account settings to permit access to smtp. - AJ X.
Possible duplicate of How to configure XAMPP to send mail from localhost? - user4412122
From Google help: Sign in to the Gmail web interface.Open the 'Forwarding and POP/IMAP' tab on your 'Settings' page, and configure IMAP or POP. After enabling this in Gmail, make sure you click 'Save Changes' so Gmail can communicate with your mail client - AJ X.
@apdulla look at the title.. - user4412122

1 Answers

0
votes

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