CodeIgniter Forums
Cannot send mails using SMTP - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: Cannot send mails using SMTP (/showthread.php?tid=65534)



Cannot send mails using SMTP - pjlyoko - 06-23-2016

Hello!

I'm trying to send mails using SMTP connecting to Office 365 account. Unfortunately it stops... Here are things I could see.

Code:
Severity: Warning --> stream_socket_enable_crypto(): SSL: crypto enabling timeout /home/ekspert/domains/szkola-ekspert.pl/danestrony/system/libraries/Email.php 2006
ERROR - 2016-06-23 17:01:30 -->

220 AM2PR09CA0019.outlook.office365.com Microsoft ESMTP MAIL Service ready at Thu, 23 Jun 2016 15:08:16 +0000
<br /><pre>hello: </pre>The following SMTP error was encountered: <br /><pre>starttls: </pre>The following SMTP error was encountered: <br />The following SMTP error was encountered: <br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br /><pre>User-Agent: CodeIgniter
Date: Thu, 23 Jun 2016 17:01:15 +0200
From: &lt;*****************************&gt;
Return-Path: &lt;*****************************&gt;
To: *****************************
Subject: =?UTF-8?Q?Wy=C5=9Bwietlono=20stron=C4=99?==?UTF-8?Q?!?=
Reply-To: &lt;*****************************&gt;
X-Sender: *****************************
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: &lt;576bf9bbbe287@*****************************&gt;
Mime-Version: 1.0


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

&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Ktoś wyświetlił stronę!&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Ktoś wyświetlił stronę eszkola w języku pl.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

The error is:
Code:
A PHP Error was encountered

Severity: Warning

Message: stream_socket_enable_crypto(): SSL: crypto enabling timeout

Filename: libraries/Email.php

Line Number: 2006

Backtrace:

File: /home/********************/domains/****************/danestrony/application/models/Pages_model.php
Line: 50
Function: send

File: /home/********************/domains/****************/danestrony/application/controllers/Pages.php
Line: 11
Function: getPage

File: /home/********************/domains/****************/public_html/index.php
Line: 338
Function: require_once

And my code:

PHP Code:
$this->load->library('email');

$this->email->from('*****************************');
$this->email->to('*****************************');
$this->email->subject('Wyświetlono stronę!');
$this->email->message('<!DOCTYPE html><html><head><title>Ktoś wyświetlił stronę!</title></head><body><p>Ktoś wyświetlił stronę ' $link ' w języku ' $lang '.</p></body></html>');
$this->email->send();

if(!
$this->email->send()) {
    
log_message('error'PHP_EOL.PHP_EOL.$this->email->print_debugger().PHP_EOL.PHP_EOL);


Config file (application/config/email.php):
Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

$config['crlf'] = '\r\n';
$config['newline'] = '\r\n';
$config['wordwrap'] = FALSE;

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.office365.com';
$config['smtp_port'] = 587;
$config['smtp_user'] = '*****************************';
$config['smtp_pass'] = '*****************************';
$config['smtp_crypto'] = 'tls';
$config['smtp_timeout'] = 5;



RE: Cannot send mails using SMTP - InsiteFX - 06-23-2016

I would check your SMTP settings in your php.ini file.

Also make sure that SSL is enabled.


RE: Cannot send mails using SMTP - pjlyoko - 06-25-2016

InsiteFx,
I tried to use https, but it didn't work. However, I don't use it because I'm using shared hosting account so I cannot use SSL certificate - may it without temporaily without it?

The php.ini settings SMTP and smtp_port are set default, but the script connects to Office 365 SMTP server as you can see in the log.

Here's log from today's try:
Code:
ERROR - 2016-06-25 15:30:01 --> Severity: Warning --> stream_socket_enable_crypto(): SSL: crypto enabling timeout /home/ekspert/domains/szkola-ekspert.pl/danestrony/system/libraries/Email.php 2006
ERROR - 2016-06-25 15:30:01 -->

220 AM5PR0501CA0039.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 25 Jun 2016 13:36:50 +0000
<br /><pre>hello: </pre>The following SMTP error was encountered: <br /><pre>starttls: </pre>The following SMTP error was encountered: <br />The following SMTP error was encountered: <br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br />Failed to send AUTH LOGIN command. Error: <br />Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.<br /><pre>User-Agent: CodeIgniter
Date: Sat, 25 Jun 2016 15:29:46 +0200
From: &lt;[email protected]&gt;
Return-Path: &lt;[email protected]&gt;
To: [email protected]
Subject: =?UTF-8?Q?Wy=C5=9Bwietlono=20stron=C4=99?==?UTF-8?Q?!?=
Reply-To: &lt;[email protected]&gt;
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: &lt;[email protected]&gt;
Mime-Version: 1.0


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

&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;&lt;title&gt;Ktoś wyświetlił stronę!&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;p&gt;Ktoś wyświetlił stronę eszkola w języku pl.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</pre>

Any ideas? I have no idea...

On the other side, I have a Moodle instance in one of subdomains and it's configured to send mails using another account. And it works perfectly well, so it must work somehow...

Thanks in advance!
Pj


RE: Cannot send mails using SMTP - pjlyoko - 02-12-2017

Hello!

I solved that problem... yesterday. It is important to set newline and crlf to
PHP Code:
"\r\n" 
, using double quotes. Then everything works.