CodeIgniter Forums
SMTP EMail sending issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: SMTP EMail sending issue (/showthread.php?tid=88950)



SMTP EMail sending issue - cycyx - 12-07-2023

Heya,
We're transitioning vom our old Windows Server running Xampp, PHP 7.4 with Codeigniter 3 to our new Windows Server running Xampp, PHP 8.1 with Codeigniter 4. Both servers are within the same network.
I've spent around an insane amount of hours re-writing the 50,000+ lines of PHP, but nothing compares to how much time I've wasted with getting a simple E-mail to send...

Here is the error I'm getting, with personalised data replaced with crap like domain.com.  The configs are 100% identical to the CI3 version.  Username, password etc is 100000% correct.
It could be a Windows issue, a PHP8.1 issue or a CI4 issue. I just can't figure this out.  Spent around 6 hours on troubleshooting and now given up and hoping someone has experienced this before.

Code:
Unable to send email using SMTP. Your server might not be configured to send mail using this method.
Date: Thu, 7 Dec 2023 15:55:50 +0000
MIME-Version: 1.0; charset=utf-8
Content-type: text/html
From: "John Doe" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Subject: =?UTF-8?Q?Test=20Email=20from=20CodeIgniter=204?=
Reply-To: <[email protected]>
User-Agent: CodeIgniter
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0




Code:
<?php

namespace App\Controllers;

use CodeIgniter\Controller;
use CodeIgniter\Email\Email;



class sendemail extends BaseController {

function __construct(){
    } 


public function index()
{
return 'nothing to see here';
}


public function phpinfo(){
phpinfo();
}

public function test(){
error_reporting(E_ALL);
    ini_set('display_errors', '1');

$email = new Email();

$config = [
'protocol'  => 'smtp',
'SMTPHost' => 'ssl://mail.domain.com',
'SMTPPort' => 465,
'SMTPUser' => '[email protected]',
'SMTPPass' => 'supersecurepassword',
'newline' => "\r\n",
'mailType'  => 'html',
'charset'  => 'utf-8',
'wordWrap'  => true
];

$email->initialize($config);

$email->setHeader('MIME-Version', '1.0; charset=utf-8');
$email->setHeader('Content-type', 'text/html');
$email->setFrom('[email protected]', 'John Doe');
$email->setTo('[email protected]');
$email->setSubject('Test Email from CodeIgniter 4');
$email->setMessage('This is a test email sent from CodeIgniter 4.');


if ($email->send()) {
echo 'Email successfully sent to [email protected]';
} else {
$data = $email->printDebugger(['headers']);
print_r($data);
}
}



RE: SMTP EMail sending issue - kenjis - 12-07-2023

'ssl://mail.domain.com' is not a hostname.


RE: SMTP EMail sending issue - cycyx - 12-08-2023

ffs, haha.
In CI3 the smtp host was ssl://mail.domain.com, but in CI4 it needs to be mail.domain.com
That was an embarrassingly easy fix...   Thanks for saving my sanity and now I'll have to have a stiff drink to wipe my memory of all of this.
Thanks!


RE: SMTP EMail sending issue - davis.lasis - 12-08-2023

(12-08-2023, 08:52 AM)cycyx Wrote: ffs, haha.
In CI3 the smtp host was ssl://mail.domain.com, but in CI4 it needs to be mail.domain.com
That was an embarrassingly easy fix...   Thanks for saving my sanity and now I'll have to have a stiff drink to wipe my memory of all of this.
Thanks!

Woderfull response. Love it. 
I guess we all been there...


RE: SMTP EMail sending issue - kenjis - 12-08-2023

Drinking too much alcohol may harm your health.

> The configs are 100% identical to the CI3 version.

It seems there are incompatible changes in the Email behavior.
So it should be documented in Upgrading Guide.
I sent a PR:
https://github.com/codeigniter4/CodeIgniter4/pull/8310

Thank you for reporting.