I have an application in Codeigniter 3 that I'm converting to Codeigniter 4, I have a problem that I can't solve by sending mail
in Codeigniter 3, in the config/email.php file I have this configuration currently working
PHP Code:
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://my.mail.server.com';
$config['smtp_port'] = '465';//465
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'MY-PASSWORD';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n";
Now in Codeigniter 4 I put the same parameters in the new configuration file in Config/Email.php
PHP Code:
namespace Config;
use CodeIgniter\Config\BaseConfig;
class Email extends BaseConfig
{
/**
* @var string
*/
public $fromEmail;
/**
* @var string
*/
public $fromName;
/**
* @var string
*/
public $recipients;
/**
* The "user agent"
*
* @var string
*/
public $userAgent = 'CodeIgniter';
/**
* The mail sending protocol: mail, sendmail, smtp
*
* @var string
*/
public $protocol = 'smtp';
/**
* The server path to Sendmail.
*
* @var string
*/
public $mailPath = '/usr/sbin/sendmail';
/**
* SMTP Server Address
*
* @var string
*/
public $SMTPHost = 'ssl://my.mail.server.com'; #
/**
* SMTP Username
*
* @var string
*/
public $SMTPUser = '[email protected]';
/**
* SMTP Password
*
* @var string
*/
public $SMTPPass = 'MY-PASSWORD';
/**
* SMTP Port
*
* @var int
*/
public $SMTPPort = 465;
/**
* SMTP Timeout (in seconds)
*
* @var int
*/
public $SMTPTimeout = 60;
/**
* Enable persistent SMTP connections
*
* @var bool
*/
public $SMTPKeepAlive = false;
/**
* SMTP Encryption. Either tls or ssl
*
* @var string
*/
public $SMTPCrypto = 'ssl'; //tls
/**
* Enable word-wrap
*
* @var bool
*/
public $wordWrap = true;
/**
* Character count to wrap at
*
* @var int
*/
public $wrapChars = 76;
/**
* Type of mail, either 'text' or 'html'
*
* @var string
*/
public $mailType = 'html';
/**
* Character set (utf-8, iso-8859-1, etc.)
*
* @var string
*/
public $charset = 'UTF-8';
/**
* Whether to validate the email address
*
* @var bool
*/
public $validate = false;
/**
* Email Priority. 1 = highest. 5 = lowest. 3 = normal
*
* @var int
*/
public $priority = 3;
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $CRLF = "\r\n";
/**
* Newline character. (Use “\r\n” to comply with RFC 822)
*
* @var string
*/
public $newline = "\r\n";
/**
* Enable BCC Batch Mode.
*
* @var bool
*/
public $BCCBatchMode = false;
/**
* Number of emails in each BCC batch
*
* @var int
*/
public $BCCBatchSize = 200;
/**
* Enable notify message from server
*
* @var bool
*/
public $DSN = false;
}
The mail is not sent and doing a debug, the result is this:
Quote:Unable to send email using SMTP. Your server might not be configured to send mail using this method.
Date: Wed, 22 Mar 2023 14:23:32 +0100
From: "Company Name" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Reply-To: "Company Name" <[email protected]>
Subject: =?UTF-8?Q?Test?=
User-Agent: CodeIgniter
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Now, what am I doing wrong in CI4?
Why does it work with the same configuration in CI3?