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

Bug: Can't Send Email Using SMTP #9448

Open
yllumi opened this issue Feb 12, 2025 · 2 comments
Open

Bug: Can't Send Email Using SMTP #9448

yllumi opened this issue Feb 12, 2025 · 2 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@yllumi
Copy link

yllumi commented Feb 12, 2025

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:

hello: 
The following SMTP error was encountered:
starttls: 
The following SMTP error was encountered:
Unable to send email using SMTP. Your server might not be configured to send mail using this method.
Date: Wed, 12 Feb 2025 17:35:25 +0700
To: [email protected]
Subject: =?UTF-8?Q?SMTP=20Email=20Testing?=
From: "Masagi" <[email protected]>
Return-Path: <[email protected]>
Reply-To: <[email protected]>
User-Agent: Tarbiyya
X-Sender: [email protected]
X-Mailer: Tarbiyya
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_67ac796d34a404.14803652"

This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ALT_67ac796d34a404.14803652
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is sample body of email testing using SMTP.


--B_ALT_67ac796d34a404.14803652
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

This is sample body of email testing using SMTP.

--B_ALT_67ac796d34a404.14803652--

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:

// CodeIgniter Email
$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();

// PHPMailer
$mail = new PHPMailer(true);
$EmailConfig = new \Config\Email;
try {
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;
    $mail->isSMTP();
    $mail->Host       = $EmailConfig->SMTPHost;
    $mail->SMTPAuth   = true;
    $mail->Username   = $EmailConfig->SMTPUser;
    $mail->Password   = $EmailConfig->SMTPPass;
    $mail->SMTPSecure = $EmailConfig->SMTPCrypto; // 'tls'
    $mail->Port       = $EmailConfig->SMTPPort; // 587

    $mail->setFrom($EmailConfig->fromEmail, $EmailConfig->fromName);
    $mail->addAddress('[email protected]');
    $mail->isHTML(true);

    $mail->Subject = 'SMTP Email Testing';
    $mail->Body    = 'This is sample body of email testing using SMTP.';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

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

@yllumi yllumi added the bug Verified issues on the current code behavior or pull requests that will fix them label Feb 12, 2025
@michalsn
Copy link
Member

I can't reproduce the problem using an email from Hostinger.

These are the only things changed in the email config.

email.fromEmail = 'hello@<private>'
email.fromName = 'This is me'
email.protocol = 'smtp'
email.SMTPHost = 'smtp.hostinger.com'
email.SMTPUser = 'hello@<private>'
email.SMTPPass = '<private>'
email.SMTPCrypto = 'tls'
email.SMTPPort = '587'
email.mailType = 'html'

The log:

220 ESMTP smtp.hostinger.com

hello: 250-smtp.hostinger.com
250-PIPELINING
250-SIZE 48811212
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 CHUNKING

starttls: 220 2.0.0 Ready to start TLS

hello: 250-smtp.hostinger.com
250-PIPELINING
250-SIZE 48811212
250-ETRN
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 CHUNKING

from: 250 2.1.0 Ok

to: 250 2.1.5 Ok

data: 354 End data with .

250 2.0.0 Ok: queued as 4YtnkF3L5YzF8gN4

quit: 221 2.0.0 Bye

Your message has been successfully sent using the following protocol: smtp

<here goes the message>

@michalsn
Copy link
Member

@yllumi Can you add something to help us reproduce the error? Without that, I'm afraid I'll have to close this issue.

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

No branches or pull requests

2 participants