发送电子邮件代码点火器错误


Sending email Codeigniter Error

>我正在尝试从本地主机使用我的代码点火器项目发送电子邮件,但它总是显示这样的错误:

    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 设置:扩展 = php_openssl.dll

有什么答案吗?

非常感谢...

$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();

论坛

堆栈溢出

你可以看看这个邮件枪。它看起来易于使用和安全。

如果您使用的是 Gmail,则必须更改您的 Gmail 帐户以允许"访问安全性较低的应用程序"。

来自 gmail

的信息 以更少的方式更改帐户访问权限 Secure apps
为了帮助确保 Google Apps 用户的帐号安全,我们 可能会阻止安全性较低的应用访问 Google 企业应用套件帐号。作为一个 谷歌企业应用用户,您将看到"密码不正确"错误,当 尝试登录。如果是这种情况,您有两种选择:

选项 1:升级到使用最新内容的更安全的应用 安全措施。所有谷歌产品,如Gmail,都使用最新的 安全措施。

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

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

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

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

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

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

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

使用代码点火器使用本地主机发送电子邮件:

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

如果您

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

以下是我发现的在本地管道

上设置发送邮件的方法,以帮助我在本地主机上发送电子邮件 https://www.youtube.com/watch?v=TO7MfDcM-Ho

XAMMP/wamp Windows Only

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

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

sendmail_path = "''"C:''Xampp''sendmail''sendmail.exe''" -t">

发送邮件

文件夹:发送邮件.ini文件

添加您自己的详细信息

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

第 18 行:smtp_port=465 或 587

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

passwordauth_username= username@demo.com

auth_password= 演示

完成所有这些操作后,您应该能够设置代码点火器邮件配置,然后发送邮件。只要 sendmail.ini 和 php.ini对 xampp/wampp 进行了更改

在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:在应用程序/配置/路由中的路由.php文件中进行更改.php并在文件末尾添加以下行:

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

有关更多详细信息,请参阅源

它对我有用。我正在 xampp 窗口上运行。

我像这样更改了一些部分

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 用户请注意:如果您的管理员锁定了安全性较低的应用帐号访问权限,此设置将被隐藏。

如果您仍然无法登录自己的帐户,则会出现"密码不正确"错误