-
akinuri
Junior Member
-
Posts: 14
Threads: 3
Joined: May 2020
Reputation:
0
I'm on Windows 10 Pro x64 and using XAMPP 7.4.4 & CI 4.1.1 on a local machine. I'm not able to send an email.
The code and the output:
PHP Code: $email = \Config\Services::email(); $config = [ "protocol" => "smtp", "SMTPHost" => "___.___.___", "SMTPPort" => 587, "SMTPUser" => "___@___.___", "SMTPPass" => "___", "newline" => "\r\n", ]; $email->initialize($config); $email->setFrom($config["SMTPUser"]); $email->setTo("___@___.___"); $email->setSubject("Hey"); $email->setMessage("Howdy?"); $email->send(false); echo $email->printDebugger();
Quote:Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in C:\xampp\htdocs\___\system\Email\Email.php on line 2103
220 ___.___.___ ESMTP ___ Corporate Mail Service; Sun, 23 May 2021 14:48:50 +0300
hello: 250-___.___.___ Hello localhost [___.___.___.___], pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-STARTTLS
250 HELP
starttls: 220 2.0.0 Ready to start TLS
The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Sun, 23 May 2021 06:48:48 -0500
From: <___@___.___>
Return-Path: <___@___.___>
To: ___@___.___
Subject: =?UTF-8?Q?Hey?=
Reply-To: <___@___.___>
User-Agent: CodeIgniter
X-Sender: ___@___.___
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <60aa4120963c59.49387580@___.___>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Howdy?
The weird thing is the same code in CI3 works:
PHP Code: $this->load->library('email'); $config = [ "protocol" => "smtp", "smtp_host" => "___.___.___", "smtp_port" => "587", "smtp_user" => "___@___.___", "smtp_pass" => "___", "newline" => "\r\n", ]; $this->email->initialize($config); $this->email->from($config["smtp_user"]); $this->email->to("___@___.___"); $this->email->subject("Hey"); $this->email->message("Howdy?"); $this->email->send(false); echo $this->email->print_debugger();
CI3 output:
Quote:220 ___.___.___ ESMTP ___ Corporate Mail Service; Sun, 23 May 2021 15:03:08 +0300
hello: 250-___.___.___ Hello localhost [___.___.___.___], pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-STARTTLS
250 HELP
from: 250 2.1.0 ... Sender ok
to: 250 2.1.5 ... Recipient ok
data: 354 Enter mail, end with "." on a line by itself
250 2.6.0 450 bytes received in 00:00:00; Message id 202105231503083047 accepted for delivery
quit: 221 2.0.0 ___.___.___ closing connection
Your message has been successfully sent using the following protocol: smtp
Date: Sun, 23 May 2021 14:03:06 +0200
From: <___@___.___>
Return-Path: <___@___.___>
To: ___@___.___
Subject: =?UTF-8?Q?Hey?=
Reply-To: <___@___.___>
User-Agent: CodeIgniter
X-Sender: ___@___.___
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <60aa447ad2853@___.___>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Howdy?
I've examined the STMP connect methods in both email classes, but couldn't find a noticable difference. If I remove the tls check, it works, but I'm not sure if that's a good idea. So what's the problem here?
05-23-2021, 06:20 AM
(This post was last modified: 05-23-2021, 06:22 AM by [email protected].)
Before looking for an in-depth solution I would suggest, as a quick and easy check, you turn off TEMPORARIALY your anti-virus software. Then try to send the email again. This is a know problem with AVG which substitutes its own certificate to check emails for viruses.
Let us know how you get on.
-
akinuri
Junior Member
-
Posts: 14
Threads: 3
Joined: May 2020
Reputation:
0
I monitored the network while trying to send mails in case it gives clues about the problem, and I think I figured it out.
Here's a successful mail send from CI3:
Code: No Time Source Destination Protocol Length Info
----------------------------------------------------------------------------------------------------
14 0.510596 ___.___.___.___ ___.___.___.___ TCP 66 63640 → 587 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 ...
15 0.551575 ___.___.___.___ ___.___.___.___ TCP 66 587 → 63640 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len= ...
16 0.551652 ___.___.___.___ ___.___.___.___ TCP 54 63640 → 587 [ACK] Seq=1 Ack=1 Win=66048 Len=0
21 0.588550 ___.___.___.___ ___.___.___.___ SMTP 145 S: 220 ___.___.___ ESMTP ___ Corporate Mail Serv ...
22 0.589183 ___.___.___.___ ___.___.___.___ SMTP 70 C: EHLO localhost
23 0.628545 ___.___.___.___ ___.___.___.___ SMTP 307 S: 250-___.___.___ Hello localhost [___.___.___. ...
24 0.628808 ___.___.___.___ ___.___.___.___ SMTP 66 C: AUTH LOGIN
27 0.668526 ___.___.___.___ ___.___.___.___ SMTP 72 S: 334 VXNnrh56bWU6
28 0.668638 ___.___.___.___ ___.___.___.___ SMTP 88 C: User: ___
30 0.697355 ___.___.___.___ ___.___.___.___ SMTP 72 S: 334 UGFzcxsf5mQ6
31 0.697514 ___.___.___.___ ___.___.___.___ SMTP 68 C: Pass: ___
33 0.749191 ___.___.___.___ ___.___.___.___ SMTP 91 S: 235 2.0.0 Authentication successful
34 0.749385 ___.___.___.___ ___.___.___.___ SMTP 90 C: MAIL FROM:<___@___.___>
35 0.788907 ___.___.___.___ ___.___.___.___ SMTP 103 S: 250 2.1.0 <___@___.___>... Sender ok
36 0.789059 ___.___.___.___ ___.___.___.___ SMTP 89 C: RCPT TO:<___@___.___>
37 0.828452 ___.___.___.___ ___.___.___.___ SMTP 107 S: 250 2.1.5 <___@___.___>... Recipient ok
38 0.828783 ___.___.___.___ ___.___.___.___ SMTP 60 C: DATA
43 0.857081 ___.___.___.___ ___.___.___.___ SMTP 104 S: 354 Enter mail, end with "." on a line by its ...
44 0.857203 ___.___.___.___ ___.___.___.___ SMTP 506 C: DATA fragment, 452 bytes
47 0.950460 ___.___.___.___ ___.___.___.___ TCP 54 587 → 63640 [ACK] Seq=570 Ack=606 Win=130560 Len ...
48 0.950516 ___.___.___.___ ___.___.___.___ SMTP/IMF 57 from: <___@___.___>, subject: =?UTF-8?Q?Hey?=,
51 0.999937 ___.___.___.___ ___.___.___.___ SMTP 149 S: 250 2.6.0 450 bytes received in 00:00:00; Mes ...
52 1.000092 ___.___.___.___ ___.___.___.___ SMTP 60 C: QUIT
53 1.049809 ___.___.___.___ ___.___.___.___ SMTP 102 S: 221 2.0.0 ___.___.___ closing connection
and the problematic one from the CI4:
Code: No Time Source Destination Protocol Length Info
----------------------------------------------------------------------------------------------------
87 3.444594 ___.___.___.___ ___.___.___.___ TCP 66 64054 → 587 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 ...
92 3.477140 ___.___.___.___ ___.___.___.___ TCP 66 587 → 64054 [SYN, ACK] Seq=0 Ack=1 Win=8192 Len= ...
93 3.477217 ___.___.___.___ ___.___.___.___ TCP 54 64054 → 587 [ACK] Seq=1 Ack=1 Win=66048 Len=0
94 3.506342 ___.___.___.___ ___.___.___.___ SMTP 145 S: 220 ___.___.___ ESMTP ___ Corporate Mail Serv ...
95 3.506506 ___.___.___.___ ___.___.___.___ SMTP 70 C: EHLO localhost
98 3.535388 ___.___.___.___ ___.___.___.___ SMTP 307 S: 250-___.___.___ Hello localhost [___.___.___. ...
99 3.535588 ___.___.___.___ ___.___.___.___ SMTP 64 C: STARTTLS
101 3.562844 ___.___.___.___ ___.___.___.___ SMTP 84 S: 220 2.0.0 Ready to start TLS
103 3.599593 ___.___.___.___ ___.___.___.___ TLSv1 571 Client Hello
104 3.656124 ___.___.___.___ ___.___.___.___ TLSv1 959 Server Hello, Certificate, Server Hello Done
105 3.656588 ___.___.___.___ ___.___.___.___ TLSv1 61 Alert (Level: Fatal, Description: Unknown CA)
110 3.691253 ___.___.___.___ ___.___.___.___ TCP 54 587 → 64054 [FIN, ACK] Seq=1280 Ack=551 Win=1305 ...
111 3.691470 ___.___.___.___ ___.___.___.___ TCP 54 64054 → 587 [ACK] Seq=551 Ack=1281 Win=64768 Len ...
112 3.698468 ___.___.___.___ ___.___.___.___ SMTP 60 C: QUIT
113 3.702807 ___.___.___.___ ___.___.___.___ TCP 54 64054 → 587 [FIN, ACK] Seq=557 Ack=1281 Win=6476 ...
Notice the difference. CI3 does not start a TLS, but the mail debugger says otherwise.
Upon further investigation, I noticed that in the email class $smtp_crypto is set to "" by default. So the TLS check in _smtp_connect() is never run.
However, in CI4, $SMTPCrypto is set to "tls" by default, so the TLS check is always run unless it's changed.
Now, to solve the problem, all I have to do is set $SMTPCrypto to "". The final state of the code:
PHP Code: $email = \Config\Services::email(); $config = [ "protocol" => "smtp", "SMTPHost" => "___.___.___", "SMTPPort" => 587, "SMTPCrypto" => "", // now it's the same as CI3 "SMTPUser" => "___@___.___", "SMTPPass" => "___", "newline" => "\r\n", ]; $email->initialize($config); $email->setFrom($config["SMTPUser"]); $email->setTo("___@___.___"); $email->setSubject("Hey"); $email->setMessage("Howdy?"); $email->send(false); echo $email->printDebugger();
and voila!
Quote:220 ______.___ ESMTP ___ Corporate Mail Service; Sun, 23 May 2021 16:58:23 +0300
hello: 250-______.___ Hello localhost [___.___.___.___], pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-STARTTLS
250 HELP
from: 250 2.1.0 ... Sender ok
to: 250 2.1.5 ... Recipient ok
data: 354 Enter mail, end with "." on a line by itself
250 2.6.0 466 bytes received in 00:00:00; Message id 202105231658233843 accepted for delivery
quit: 221 2.0.0 ______.___ closing connection
Your message has been successfully sent using the following protocol: smtp
Date: Sun, 23 May 2021 08:58:21 -0500
From: <___@___.___>
Return-Path: <___@___.___>
To: ___@___.___
Subject: =?UTF-8?Q?Hey?=
Reply-To: <___@___.___>
User-Agent: CodeIgniter
X-Sender: ___@___.___
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <60aa5f7d96a295.26287360@___.___>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Howdy?
While I managed to pinpoint the source of the problem and make it work, I still need a word from the team. Is it safe to set SMTPCrypto to an empty string? If not, that's how the email class works in CI3. Why the change?
If I shouldn't be setting SMTPCrypto to an empty string, how do I solve the problem? Especially on the localhost?
One solution that comes to mind is that modifying SMTPCrypto depending on the environment or something else.
-
InsiteFX
Super Moderator
-
Posts: 6,498
Threads: 321
Joined: Oct 2014
Reputation:
239
-
paliz
Member
-
Posts: 236
Threads: 19
Joined: Oct 2020
Reputation:
1
here my code
PHP Code: <?php
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='yourhost.com';
/** * SMTP Username * * @var string */ public $SMTPUser='[email protected]';
/** * SMTP Password * * @var string */ public $SMTPPass='yourpass';
/** * SMTP Port * * @var integer */ public $SMTPPort = 465;
/** * SMTP Timeout (in seconds) * * @var integer */ public $SMTPTimeout = 5;
/** * Enable persistent SMTP connections * * @var boolean */ public $SMTPKeepAlive = false;
/** * SMTP Encryption. Either tls or ssl * * @var string */ public $SMTPCrypto = 'tls';
/** * Enable word-wrap * * @var boolean */ public $wordWrap = true;
/** * Character count to wrap at * * @var integer */ public $wrapChars = 76;
/** * Type of mail, either 'text' or 'html' * * @var string */ public $mailType = 'text';
/** * Character set (utf-8, iso-8859-1, etc.) * * @var string */ public $charset = 'UTF-8';
/** * Whether to validate the email address * * @var boolean */ public $validate = false;
/** * Email Priority. 1 = highest. 5 = lowest. 3 = normal * * @var integer */ 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 boolean */ public $BCCBatchMode = false;
/** * Number of emails in each BCC batch * * @var integer */ public $BCCBatchSize = 200;
/** * Enable notify message from server * * @var boolean */ public $DSN = false;
}
PHP Code: $email =\Codeigniter\Config\Services::email(); $emailConfig = new \Config\Email();
$email->setFrom($emailConfig->fromEmail, $emailConfig->fromName); $email->setTo($contacting['email']); $email->setSubject( lang('Common.apiEvent.emailReply').' '. $contacting['title'] ); $email->setMessage($this->request->getJSON()->reply); $result = $email->send();
// print_r( $email->printDebugger());
Enlightenment Is Freedom
-
InsiteFX
Super Moderator
-
Posts: 6,498
Threads: 321
Joined: Oct 2014
Reputation:
239
if your on Windows you need to use a mail server like I mentioned above, also set the
smtp in php.ini to a hosting provider.
Best way to test on local is to use like google gmail.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
-
akinuri
Junior Member
-
Posts: 14
Threads: 3
Joined: May 2020
Reputation:
0
Guys, I appreciate the answers, but it appears none of you really examined the issue (the things I've posted).
No, the problem is not about an antivirus software. As I said, the email class in CI3 works, but the one in CI4 didn't work. This suggests that the problem is/was about CI4.
The code I've posted above is not arbitrary. It's something that I've tested. And I'm using the port 587. Also, I've mentioned using XAMPP. So all this is on dev/localhost.
Of course, it works on a live server (probably because you have a certificate there).
There's nothing wrong with the email server. The code works on a live server.
The problem is about the way email class in CI4 works. It's not the same as the email class in CI3.
I've already found the source of the problem, and managed to work around it. Now, all I need is an explanation.
|