Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Email class may not log an error when it fails to send #6362

Merged
merged 2 commits into from
Aug 10, 2022

Conversation

kenjis
Copy link
Member

@kenjis kenjis commented Aug 9, 2022

Description
Fixes #6350

Before:
no log

After:

ERROR - 2022-08-08 23:13:22 --> Email: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
ERROR - 2022-08-08 23:13:22 --> 220 smtp.googlemail.com ESMTP s1-20020a17090a2f0100b001f04479017fsm9022783pjd.29 - gsmtp

hello: 250-smtp.googlemail.com at your service, [133.149.85.47]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8

starttls: 220 2.0.0 Ready to start TLS

hello: 250-smtp.googlemail.com at your service, [133.149.85.47]
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: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8  https://support.google.com/mail/?p=BadCredentials s1-20020a17090a2f0100b001f04479017fsm9022783pjd.29 - gsmtp

How to Test

<?php

namespace App\Controllers;

class Home extends BaseController
{
    public function index()
    {
        $email = \Config\Services::email();

        $config['protocol']   = 'smtp';
        $config['SMTPHost']   = 'smtp.googlemail.com';
        $config['SMTPUser']   = 'test@gmail.com';
        $config['SMTPPass']   = 'passwd';
        $config['SMTPPort']   = 587;
        $config['SMTPCrypto'] = 'tls';

        $email->initialize($config);

        $email->setFrom('your@example.com', 'Your Name');
        $email->setTo('someone@example.com');
        $email->setSubject('Email Test');
        $email->setMessage('Testing the email class.');

        $email->send();

        d($email->printDebugger('headers'));
    }
}

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 9, 2022
Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change! I'm so ready to be rid of this class... what a mess it can be.

@kenjis kenjis merged commit 9204889 into codeigniter4:develop Aug 10, 2022
@kenjis kenjis deleted the fix-email-logging branch August 10, 2022 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Email class may not log an error when it fails to send
3 participants