代码之家  ›  专栏  ›  技术社区  ›  PrakashT

代码点火器邮件功能在“我的本地”中运行良好,但在“实时”和“引发错误”中运行不正常

  •  0
  • PrakashT  · 技术社区  · 6 年前

    我的codeigniter邮件功能在本地运行良好,但同一代码无法实时运行并引发错误。

    我认为这个错误是密码不匹配。但我检查了密码,密码是对的

    以下是我的错误消息:

    An Error Was Encountered
    
    220 smtp.googlemail.com ESMTP s189-v6sm30071511pgc.39 - gsmtp
    
    hello: 250-smtp.googlemail.com at your service, [181.224.149.217]
    250-SIZE 35882577
    250-8BITMIME
    250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH
    250-ENHANCEDSTATUSCODES
    250-PIPELINING
    250-CHUNKING
    250 SMTPUTF8
    
    Failed to authenticate password. Error: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/answer/78754 s189-v6sm30071511pgc.39 - gsmtp
    Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
    
    User-Agent: CodeIgniter
    Date: Sat, 5 May 2018 14:39:51 +0530
    To: tprakash11121996@gmail.com
    From: "MyWebsite" <tprakashkce@gmail.com>
    Return-Path: <tprakashkce@gmail.com>
    Subject: =?utf-8?Q?=48=6F=77=20=74=6F=20=73=65=6E=64=20=65=6D=61=69=6C=20=76=69=61?= =?utf-8?Q?=20=53=4D=54=50=20=73=65=72=76=65=72=20=69=6E=20=43=6F=64=65=49?= =?utf-8?Q?=67=6E=69=74=65=72?=
    Reply-To: "tprakashkce@gmail.com" <tprakashkce@gmail.com>
    X-Sender: tprakashkce@gmail.com
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <5aed74df89302@gmail.com>
    Mime-Version: 1.0
    
    
    Content-Type: multipart/alternative; boundary="B_ALT_5aed74df89342"
    
    This is a multi-part message in MIME format.
    Your email application may not support this format.
    
    --B_ALT_5aed74df89342
    Content-Type: text/plain; charset=utf-8
    Content-Transfer-Encoding: 8bit
    
    Billed Patient DetailsDear Sir/madam, We are attached billed patient files
    in this mail
    
    
    --B_ALT_5aed74df89342
    Content-Type: text/html; charset=utf-8
    Content-Transfer-Encoding: quoted-printable
    
    =3Ch1=3EBilled Patient Details=3C/h1=3E=3Cp=3EDear Sir/madam,=3Cbr=3E We ar=
    e attached billed patient files in this mail=3C/p=3E
    
    --B_ALT_5aed74df89342--
    

    我也试图更改端口号,但没有用 在这里,我将清空我的密码。但我还是要说密码是正确的

    这是我的代码:

      public function sendMail(){
    
            $this->load->library('email');
    
            //SMTP & mail configuration
            $config = array(
                'protocol'  => 'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => 465,
                'smtp_user' => 'example@gmail.com',
                'smtp_pass' => '*********',
                'mailtype'  => 'html',
                'charset'   => 'utf-8'
            );
            $this->email->initialize($config);
            $this->email->set_mailtype("html");
            $this->email->set_newline("\r\n");
    
            //Email content
            $htmlContent = '<h1>Billed Patient Details</h1>';
            $htmlContent .= '<p>Dear Sir/madam,<br> We are attached billed patient files in this mail</p>';
    
            $this->email->to('tprakash11121996@gmail.com');
            $this->email->from('tprakashkce@gmail.com','MyWebsite');
            $this->email->subject('How to send email via SMTP server in CodeIgniter');
            $this->email->message($htmlContent);
    
            if($this->email->send()){
                echo "Mail Succesfully send";
            }
            else{
                show_error($this->email->print_debugger());
            }
            }
    

    为什么会在live中引发错误?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Bibhudatta Sahoo    6 年前

    正如你所说,密码是正确的,但它说的是密码不匹配,因为谷歌限制你登录谷歌邮件。

    要发送消息,您需要更改google帐户中的某些设置。

    要做到这一点,请先登录您的google帐户,然后转到 https://myaccount.google.com/lesssecureapps 在此处打开 允许不太安全的应用

    然后转到 https://accounts.google.com/b/0/displayunlockcaptcha 在这里,允许谷歌访问,然后再试一次,它将工作。