Welcome Guest, Not a member yet? Register   Sign In
Send mail from CI4, same configuration as CI3 doesn't work
#1

(This post was last modified: 03-23-2023, 12:44 AM by serialkiller.)

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?
Reply
#2

Check the following posts:
https://forum.codeigniter.com/showthread...pid=402758
https://forum.codeigniter.com/showthread...pid=394631
Maybe this helps you.
Reply
#3

(03-22-2023, 09:32 AM)JustJohnQ Wrote: Check the following posts:
https://forum.codeigniter.com/showthread...pid=402758
https://forum.codeigniter.com/showthread...pid=394631
Maybe this helps you.

I can't find an answer to my problem
Reply
#4

if you have a google email account you can try using that . eg smtp.gmail.com

The "username" will be your google email address, and you can use 2 step security function to generate a password , specifically for use of sending emails from your web.


this line looks a bit odd not even mentioning SMTP
Code:
public $SMTPHost = 'ssl://cpanel.adamisgroup.it'; #

I don't use CI4 for sending emails , instead I use PHPMailer which you can install using composer. It works on my apache web dev on Arch Linux, so I can play about with it and test it with catch blocks ; and it works fine from live hosting .
CMS CI4     I use Arch Linux by the way 

Reply
#5

(03-22-2023, 11:49 AM)captain-sensible Wrote: if you have a google email account you can try using that .  eg        smtp.gmail.com

The "username" will be your google email address, and you can use  2 step security  function to generate  a password , specifically for use of sending emails from your web.


this line looks a bit odd not even mentioning SMTP
Code:
public $SMTPHost = 'ssl://cpanel.adamisgroup.it'; #

I don't use  CI4  for sending emails , instead I use PHPMailer  which you can install using composer. It works on my  apache  web dev on Arch Linux, so I can play about with it and test it with catch blocks ; and it works fine from live hosting .

It's not a matter of trying with different things, the question is why with the same configurations it works in CI3 and not in CI4, what's different, what needs to be changed, modified or whatever
Reply
#6

(This post was last modified: 03-23-2023, 04:04 AM by kenjis.)

CI4 is still being continuously improved; most CI3 config works fine, but not all are the same.
Or this may be just a bug.

Try
PHP Code:
public $SMTPHost 'cpanel.adamisgroup.it'
Reply
#7

@serialkiller Your CI3 config does not have smtp_crypto, but CI4 config has SMTPCrypto = 'ssl'.
These configs are not the same.
Reply
#8

(03-23-2023, 04:13 AM)kenjis Wrote: @serialkiller Your CI3 config does not have smtp_crypto, but CI4 config has SMTPCrypto = 'ssl'.
These configs are not the same.

kenjis, you are always irreplaceable, thank you so much, truly Smile
Reply




Theme © iAndrew 2016 - Forum software by © MyBB