【问题标题】:Sending email Codeigniter Error发送电子邮件 Codeigniter 错误
【发布时间】:2015-03-17 10:16:45
【问题描述】:

我正在尝试从本地主机发送带有我的 codeigniter 项目的电子邮件,但它总是显示如下错误:

    220 mx.google.com ESMTP pp9sm11498734pbb.65 - gsmtp 

hello: 250-mx.google.com at your service, [202.43.95.33]
250-SIZE 35882577
250-8BITMIME
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-CHUNKING
250 SMTPUTF8
Failed to authenticate password. Error: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp 
from: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp 
to: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp 
data: 530-5.5.1 Authentication Required. Learn more at
530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp
The following SMTP error was encountered: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 pp9sm11498734pbb.65 - gsmtp 
502 5.5.1 Unrecognized command. pp9sm11498734pbb.65 - gsmtp 
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. pp9sm11498734pbb.65 - gsmtp 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Mon, 19 Jan 2015 12:49:08 +0100
From: "andhika" <mytest@gmail.com>
Return-Path: <mytest@gmail.com>
To: coba@gmail.com
Subject: =?utf-8?Q?test?=
Reply-To: "mytest@gmail.com" <mytest@gmail.com>
X-Sender: mytest@gmail.com
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <54bcef349adf6@gmail.com>
Mime-Version: 1.0


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

world

这是我的控制器:

$this->load->library('email');
    $config = array(
                'protocol'  =>  'smtp',
                'smtp_host' =>  'ssl://smtp.googlemail.com',
                'smtp_user' =>  'mytest@gmail.com',
                'smtp_pass' =>  'youpassword',
                'smtp_port' =>  '465'
                );
    $this->email->initialize($config);
    $this->email->set_newline('\r\n');

    $this->email->from('mytest@gmail.com', 'andhika');
    $this->email->to('coba@gmail.com');
    $this->email->subject('test');
    $this->email->message('world');


    if ($this->email->send()){
         echo 'Your e-mail has been sent';
    }         
    else{
        show_error($this->email->print_debugger());
    }

这是在我的 php.ini 设置中:extension=php_openssl.dll

有答案吗?

非常感谢...

【问题讨论】:

    标签: php codeigniter email


    【解决方案1】:
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'username',
        'smtp_pass' => 'password',
        'mailtype'  => 'html', 
        'charset'   => 'iso-8859-1'
    );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    
    $result = $this->email->send();
    

    Forum

    stackoverflow

    你可以看看这个Mailgun。它看起来非常易于使用且安全。

    【讨论】:

    • 有什么方法可以让我在配置中散列或隐藏我的 smtp 密码。我们肯定不想使用纯文本密码。
    【解决方案2】:

    如果您使用的是 gmail,则必须更改您的 gmail 帐户以允许“访问不太安全的应用程序”。

    来自 gmail 的信息

    以更少的成本更改帐户访问权限 保护应用程序
    为了帮助保护 Google Apps 用户的帐户安全,我们 可能会阻止不太安全的应用访问 Google Apps 帐户。作为一个 Google Apps 用户,您将在以下情况下看到“密码不正确”错误 尝试登录。如果是这种情况,您有两种选择:

    选项 1:升级到使用最新版本的更安全的应用 安防措施。所有 Google 产品(例如 Gmail)都使用最新的 安防措施。

    选项 2:更改设置以降低安全性 应用程序来访问您的帐户。我们不推荐此选项,因为它 可能会使某人更容易闯入您的帐户。如果你 仍然要允许访问,请按照下列步骤操作:转到“更少 我的帐户中的安全应用程序”部分。旁边的“访问安全性较低 应用程序”,选择开启。
    (Google Apps 用户注意:此设置是 如果您的管理员锁定了不太安全的应用程序帐户,则隐藏 访问。)如果您仍然无法登录您的帐户,“密码 错误”错误可能是由其他原因引起的。

    【讨论】:

      【解决方案3】:

      如果有人有兴趣,我发现在设置newline时使用单引号,例如

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

      引发密码错误。它需要双引号:

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

      或者可以用双引号在$config数组中初始化:

      $config = array('newline' => "\r\n");
      

      【讨论】:

        【解决方案4】:

        使用 codeigniter 与本地主机发送电子邮件:

        如果您使用 wampp / xampp,您需要在发送邮件 ini 文件和 php ini 文件中设置您的默认电子邮件和用户名

        如果您没有设置以下功能,即使您在 codeingiter config 中设置了电子邮件,本地主机大部分时间也不会让您发送邮件。

        这是我发现的如何在本地 YouTube 上设置发送邮件的教程,可以帮助我在本地主机上发送电子邮件 https://www.youtube.com/watch?v=TO7MfDcM-Ho

        xammp/wamp 仅限 Windows

        php文件夹转到php.ini在第1142行找到取消注释

        ;sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t"

        sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t"

        sendmail 文件夹: sendmail.ini 文件

        添加您自己的详细信息

        第 14 行:smtp_server=gmail.com 主机服务器

        第 18 行:smtp_port=465 或 587

        在第 46 行和第 47 行,您需要添加用户名和

        passwordauth_username=username@demo.com

        auth_password= 演示

        一旦完成,您应该能够设置您的 codeigniter 邮件配置,然后发送邮件。只要sendmail.ini和php.ini对xampp/wampp做了修改

        【讨论】:

          【解决方案5】:

          在 Codeigniter 中发送电子邮件很简单,您只需要两个步骤:

          步骤#1:创建控制器

          <?php
          class Sendingemail_Controller extends CI_Controller {
              function __construct() {
                  parent::__construct();
                  $this->load->library('session');
                  $this->load->helper('form');
              }
              public function index() {
                  $this->load->helper('form');
                  $this->load->view('contact_email_form');
              }
              public function send_mail() {
                  $from_email = "email@example.com";
                  $to_email = $this->input->post('email');
                  //Load email library
                  $this->load->library('email');
                  $this->email->from($from_email, 'Identification');
                  $this->email->to($to_email);
                  $this->email->subject('Send Email Codeigniter');
                  $this->email->message('The email send using codeigniter library');
                  //Send mail
                  if($this->email->send())
                      $this->session->set_flashdata("email_sent","Congragulation Email Send Successfully.");
                  else
                      $this->session->set_flashdata("email_sent","You have encountered an error");
                  $this->load->view('contact_email_form');
              }
          }
          ?>
          

          步骤#2:创建视图

          <html>
          <head>    
              <title> Send Email Codeigniter </title>
          </head>
          <body>
          <?php
          echo $this->session->flashdata('email_sent');
          echo form_open('/Sendingemail_Controller/send_mail');
          ?>
          <input type = "email" name = "email" required />
          <input type = "submit" value = "SEND MAIL">
          <?php
          echo form_close();
          ?>
          </body>
          </html>
          

          步骤#3:在 application/config/routes.php 中的 routes.php 文件中进行更改,并在文件末尾添加以下行:

          $route['email'] = 'Sendingemail_Controller';
          

          更多详情请见source

          【讨论】:

            【解决方案6】:

            它对我有用。我在 xampp windows 上运行。

            我改变了一些这样的部分

            php folder go to php.ini find on line 1142 uncomment
            
            ;sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t"
            

            sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t"
            sendmail folder: sendmail.ini file
            

            添加您自己的详细信息

            第 14 行:smtp_server=gmail.com hostserver

            第 18 行:smtp_port=465 or 587 在第 46 和 47 行,您需要添加用户名和

            passwordauth_username= ***@***.com //change to yours
            
            auth_password= ****** ////change to yours
            

            我更改了 gmail 设置,因为我使用的是 gmail。

            更改您的设置以允许不太安全的应用访问您的帐户。我们不建议使用此选项,因为它可能会使某人更容易侵入您的帐户。

            如果您仍然想允许访问,请按照以下步骤操作:

            1. 转到“我的帐户”中的“安全性较低的应用程序”部分。
            2. 在“访问安全性较低的应用程序”旁边,选择打开。

            (Google Apps 用户注意:如果您的管理员锁定了不太安全的应用帐户访问权限,则此设置会隐藏。)

            如果您仍然无法登录您的帐户,“密码不正确”错误

            【讨论】:

              猜你喜欢
              • 2016-05-06
              • 2016-09-02
              • 2013-01-07
              • 2019-08-07
              • 1970-01-01
              • 1970-01-01
              • 2018-05-24
              • 2012-12-16
              • 2015-04-09
              相关资源
              最近更新 更多