I'm trying to send a email from Office 365 using PHP Code-Igniter. But I got an error:
220 MAXPR0101CA0041.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 26 Dec 2017 11:17:56 +0000
hello: 250-MAXPR0101CA0041.outlook.office365.com Hello [115.96.169.89]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
Failed to send AUTH LOGIN command. Error: 504 5.7.4 Unrecognized authentication type [MAXPR0101CA0041.INDPRD01.PROD.OUTLOOK.COM]
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Tue, 26 Dec 2017 12:17:56 +0100
From:
Return-Path:
To: myemail@mydomain.com
Subject: =?UTF-8?Q?Test=20Email?=
Reply-To:
User-Agent: CodeIgniter
X-Sender: myemail@mydomain.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a422fe430795@mydomain.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5a422fe4307e9"
This is a multi-part message in MIME format. Your email application may not support this format.
--B_ALT_5a422fe4307e9 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit
SMTP sending test email, Done...
--B_ALT_5a422fe4307e9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
SMTP sending test email, Done...
--B_ALT_5a422fe4307e9--
Here is my Controller code:
public function emailSend()
{
# code...
/*
Minimun test code for successful email sending over SMTP with Office 365
Things to double-check:
- openssl php extension must be enabled in the server
- host set to smtp.office365.com, not the old aliases
- Port 587
- newline configuration: explicit to "\r\n"
*/
//In your Controller code:
$this->load->library('email');
//$config = [
$config['protocol']= 'smtp';
$config['mailpath']= "/usr/lib/sendmail";
$config['smtp_port']= 587;
$config['smtp_timeout'] = '7';
$config['smtp_host']= 'smtp-mail.outlook.com';
$config['smtp_user']= 'myemail@mydomain.com';
$config['smtp_pass']= '*********';
$config['smtp_crypto']= 'STARTTLS';
$config['newline']= "\r\n"; //REQUIRED! Notice the double quotes!
$config['crlf']= "\r\n";
$config['mailtype'] = 'html';
//];
$this->email->initialize($config);
$this->email->from('myemail@mydomain.com');
$this->email->to('myemail@mydomain.com');
$this->email->subject('Test Email');
$this->email->message('SMTP sending test email, Done...');
$sent = $this->email->send();
if ($sent)
{
echo 'OK';
} else {
echo $this->email->print_debugger();
}
}
I had check lots of links and questions, but no success. I'm not getting what is exact error in code.
Note: I'm tried
$config['smtp_port']= 465;
$config['smtp_crypto']= 'TLS';
$config['smtp_crypto']= 'SSL';
Any kind of help is welcome, thanks in advance.