我使用打印调试器检查它是否已发送,以及我得到的回报:
bool(false) 220 smtp.gmail.com ESMTP t8sm1776565pgr.21 - gsmtp
hello: 250-smtp.gmail.com at your service, [45.116.123.5]
250-SIZE 35882577
250-8BITMIME
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. t8sm1776565pgr.21 - gsmtp
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Fri, 2 Feb 2018 13:02:25 +0530
To: demo@example.com
From: "MyWebsite" <demo@example.com>
Return-Path: <demo@example.com>
Subject: =?UTF-8?Q?How=20to=20send=20email=20vi?==?UTF-8?Q?a=20SMTP=20?= =?UTF-8?Q?server=20in=20CodeIgniter?=
Reply-To: <demo@example.com>
User-Agent: CodeIgniter
X-Sender: demo@example.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a741409bc741@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5a741409bc741"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5a741409bc741
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Sending email via SMTP serverThis email has sent via SMTP server from
CodeIgniter application.
--B_ALT_5a741409bc741
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=3Ch1=3ESending email via SMTP server=3C/h1=3E=3Cp=3EThis email has sent vi=
a SMTP server from CodeIgniter application.=3C/p=3E
--B_ALT_5a741409bc741--
当我将smtp_port更改为465时,我得到了响应,如
bool(false)
hello: F
The following SMTP error was encountered: F
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
Date: Fri, 2 Feb 2018 13:12:43 +0530
To: demo@example.com
From: "MyWebsite" <demo@example.com>
Return-Path: <demo@example.com>
Subject: =?UTF-8?Q?How=20to=20send=20email=20vi?==?UTF-8?Q?a=20SMTP=20?= =?UTF-8?Q?server=20in=20CodeIgniter?=
Reply-To: <demo@example.com>
User-Agent: CodeIgniter
X-Sender: demo@example.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5a7416736d6ea@gmail.com>
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="B_ALT_5a7416736d6ea"
This is a multi-part message in MIME format.
Your email application may not support this format.
--B_ALT_5a7416736d6ea
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Sending email via SMTP serverThis email has sent via SMTP server from
CodeIgniter application.
--B_ALT_5a7416736d6ea
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
=3Ch1=3ESending email via SMTP server=3C/h1=3E=3Cp=3EThis email has sent vi=
a SMTP server from CodeIgniter application.=3C/p=3E
--B_ALT_5a7416736d6ea--
出于安全考虑,我已将此电子邮件ID隐藏在此问题中。
我找到了很多代码示例,他们想要更改本地php.ini和sendmail.ini文件以发送电子邮件,但我认为这不是使用smtp发送邮件的要求。
我也使用PHPmailer lib,它适用于smtp邮件,但为什么CodeIgniter电子邮件lib for SMTP不起作用?此CodeIgniter SMTP设置支持哪个PHP版本?
答案 0 :(得分:0)
试试这个: -
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "mail.google.com";
$config['smtp_port'] = "26";
$config['smtp_user'] = "********@gmail.com";
$config['smtp_pass'] = "************";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('*********@gmail.com');
$email_body = "Sending Email from server.";
$this->email->to($userEmail']);
$this->email->subject('Email Subject');
$this->email->message($email_body);
$email = $this->email->send();