尝试使用smtp发送电子邮件,并手动设置apache-server和php 7.2?

时间:2019-04-30 07:53:00

标签: php apache codeigniter smtp

我正在用apache-server和php 7.2运行我的服务器。我想做的是使用C.I.中的电子邮件库发送电子邮件但我收到一个无法调试的错误。我们将不胜感激。在gmail中,已启用设置中的imap选项。  这是我的代码-

function emailverification()
    {
             $this->load->library('email');
        ini_set("SMTP","ssl://smtp.gmail.com");
                ini_set("smtp_port","465");
                $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.gmail.com';
        $config['smtp_port'] = '465';
            $config['_smtp_auth']=TRUE;
            $config['smtp_user'] = '******';
            $config['smtp_pass'] = '******';
            $config['smtp_timeout'] = '60';
            $config['charset'] = 'utf-8';
            $config['wordwrap'] = TRUE;
            $config['mailtype'] = "html";
            $this->email->initialize($config);

             $this->email->from('******', 'Support Team');
            $this->email->to('*******');

            $this->email->subject('This is my subject');
            $this->email->message('This is the content of my message');

            if ( ! $this->email->send())
            {
                show_error($this->email->print_debugger());
            }
            else
            {
                echo('DONE');
            }

    }

我还尝试将端口更改为25,587,并将主机也更改为smtp.gmail.com。这是我不断的错误信息 '遇到以下SMTP错误: 遇到以下SMTP错误: 无法使用PHP SMTP发送电子邮件。您的服务器可能未配置为使用此方法发送邮件。'

下面是附带的代码,当我运行该方法时,浏览器向我提供以下输出。尽管在编辑端口和主机名时,“尽管PHPsmtp,服务器仍无法发送邮件”。

220 smtp.gmail.com ESMTP c62sm82383961pfg.33 - gsmtp 

hello 250-smtp.gmail.com at your service, [43.252.26.109]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
from: 250 2.1.0 OK c62sm82383961pfg.33 - gsmtp
to: 250 2.1.5 OK c62sm82383961pfg.33 - gsmtp
data: 354  Go ahead c62sm82383961pfg.33 - gsmtp

quit: 
The following SMTP error was encountered: 
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: Tue, 30 Apr 2019 12:35:48 +0530
From: "Support Team" <********>
Return-Path: <*********>
To: **********
Subject: =?UTF-8?Q?This=20is=20my=20subject?=
Reply-To: <*********>
User-Agent: CodeIgniter
X-Sender: ********
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5cc7f3ccb9ee7@*****.com>
Mime-Version: 1.0


Content-Type: multipart/alternative; boundary="B_ALT_5cc7f3ccba2cf"

This is a multi-part message in MIME format.
Your email application may not support this format.

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

This is the content of my message


--B_ALT_5cc7f3ccba2cf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

This is the content of my message

--B_ALT_5cc7f3ccba2cf--

注意:

我想了解一下什么机器正在尝试告诉我,因为我对此并不陌生。 如果有人可以帮助我解决此错误,那将是非常有用的帮助。过去一周我一直在努力解决此问题,

220 smtp.gmail.com ESMTP c62sm82383961pfg.33 - gsmtp 

hello: 250-smtp.gmail.com at your service, [43.252.26.109]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
from: 250 2.1.0 OK c62sm82383961pfg.33 - gsmtp
to: 250 2.1.5 OK c62sm82383961pfg.33 - gsmtp
data: 354  Go ahead c62sm82383961pfg.33 - gsmtp

P.S。 不要拒绝投票,因为我真的很努力地获得一些积分。

1 个答案:

答案 0 :(得分:0)

解决方案1:尝试添加

$this->email->set_newline("\r\n");

之后

$this->email->from('******', 'Support Team');

解决方案2:在您的电子邮件配置文件中更改此

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

对此

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

解决方案3(但认为不会对您有帮助):当我遇到相同的问题时,上述解决方案均无法帮助我解决问题。我以某种方式通过限制主题中的字符数来修复它(经过数小时的调试,我发现仅当主题超过119个字符时它才崩溃)