-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: Can't Send Email Using SMTP #9448
Comments
I can't reproduce the problem using an email from Hostinger. These are the only things changed in the email config.
The log:
|
@yllumi Can you add something to help us reproduce the error? Without that, I'm afraid I'll have to close this issue. |
i get the same problem, is there any special settings if the application running on a linux server? |
I don't think so. Do you get the same error with this email provider or a different one? Can you provide any more details? |
@warcooft
Check if your mail server is using PLAIN or LOGIN SMTP Authentication method, this error could occur because if your mail server is using AUTH PLAIN (most likely) because CI4 by default is using AUTH LOGIN (a bit older authentication method) and as per my knowledge it is not possible to change the AUTH method simply and difference is: Because of that Email.php class needs adjustment within SMTPAuthenticate() function to handle LOGIN/PLAIN mechanism Can you just replace within System\Email.php SMTPAuthenticate() function with this one and report back if email is sent now?
|
@michalsn this is my code $email = service("email");
$email->setTo("[email protected]");
$email->setSubject("SMTP Email Testing");
$email->setMessage("This is sample body of email testing using SMTP.");
$email->send(false);
echo $email->printDebugger(); and this is my only configuration:
I also tried in fresh install of CodeIgniter 4.6.0 and it is still showing same error. |
@ip-qi I've tried to change the content of SMTPAuthenticate() as you recommend and nothing happen, still shown same error. I've tried to debug and I thought the problem occured since calling SMTPConnect(). |
@yllumi I dont think your issue is related to my example code. I asked @warcooft to try it because i didnt know his email provider and his actual use case but this same issue i personally had due to the AUTH PLAIN method not being implemented in CI and code i provided is my personal current "fix" which let me send emails using SMTP PLAIN method. (didnt reported is as no one seems to use AUTH PLAIN method but i thought @warcooft might be having that kind of issue so i gave a "wild guess"). Since you are using Hostinger and Hostinger is using same AUTH LOGIN method as CodeIgniter too and since @michalsn tried and sent successfully email the issue is likely somewhere else in your case. Have you tried using email client like Mozilla Thunderbird to receive and send emails? If you can add your email account and send/receive mails there is likely issue somewhere within your CI4 code. If Email client cant receive/send email it could be some misconfiguration on your email server side.. (not an expert in the field but just giving you few extra steps to try and find the cause) |
@ip-qi OP was able to successfully send emails using PHPMailer. @yllumi It looks like the SMTP timeout might be causing the issue. By default, // edit |
Aah, your guess was right @michalsn ! I set SMTP timeout to 30 seconds and finally CodeIgniter successfully sends SMTP email. Interestingly, I tried changing the timeout in phpmailer to 5 seconds hardcoded and it still managed to send SMTP message. Whether this is because PHPMailer prioritizes the use of |
@yllumi I'm glad it worked for you.
IMO, the default timeout is okay, but we could benefit from improved timeout handling and debug messages for it. If you feel "the inner call" feel free to send improvements.
Yes, you're right. I only looked at the method while
From what I see, this is because PHPMailer sets |
@ip-qi If you prepare a PR with AUTH PLAIN, I think we will accept it without problems - however, you need to prepare a config option for it. |
Sure, i added And also i added in email.rst appropriate changes to reflect additional config parameter Also PR is on the way |
PHP Version
8.3
CodeIgniter4 Version
4.6.0
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Linux
Which server did you use?
fpm-fcgi
Database
No response
What happened?
I've tried to setup email sender using CodeIgniter Email class. I use SMTP configuration with SMTPCrypto=tls, SMTPPort=587 and other auth configuration. Then it shows this debug message:
For comparison, I try to use PHPMailer package with same configuration I've set in Config\Email class and it sent the message successfully. I use SMTP account from Hostinger.
Steps to Reproduce
This is my sample code:
Expected Output
I don't know if I missed something in my configuration or if there is an error in the Email class.
Anything else?
No response
The text was updated successfully, but these errors were encountered: