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

Php 发送电子邮件代码点火器错误,php,codeigniter,email,Php,Codeigniter,Email,我试图从本地主机发送带有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-ENH

我试图从本地主机发送带有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
这在我的php.ini设置中:extension=php\u 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();


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

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

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

如果您没有设置以下功能,即使您在codeingiter配置中设置了电子邮件,本地主机大多数情况下也不允许您发送邮件

下面是如何设置在本地YouTube上发送邮件的教程,我找到了该教程,可以帮助我在本地主机上发送电子邮件

xammp/wamp仅限Windows

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

);sendmail\u path=“\”C:\Xampp\sendmail\sendmail.exe\”-t

sendmail\u path=“\”C:\Xampp\sendmail\sendmail.exe\”-t

sendmail文件夹:sendmail.ini文件

添加您自己的详细信息

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

第18行:smtp_端口=465或587

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

passwordauth\u用户名=username@demo.com

auth_password=demo


完成这些之后,您应该能够设置codeigniter邮件配置,然后发送邮件。只要sendmail.ini和php.ini对xampp/wampp进行了更改(如果您使用的是gmail),您的gmail帐户就必须更改为允许“访问不太安全的应用程序”

来自gmail的信息

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

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

选项2:更改设置以降低安全性 用于访问您的帐户的应用程序。我们不推荐此选项,因为它 可能会让某人更容易闯入你的帐户。如果你 要允许访问,请执行以下步骤:转到“较少” 我的帐户中的“安全应用”部分。“不太安全的访问”旁 “应用”,选择“打开”
(谷歌应用程序用户注意:此设置为 如果管理员已锁定不太安全的应用程序帐户,则隐藏 如果您仍然无法登录到您的帐户,请输入“密码” “不正确”错误可能是由其他原因引起的


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

$this->email->set_newline('\r\n');
抛出一个密码错误。它需要双引号:

$this->email->set_newline("\r\n");
$config = array('newline' => "\r\n");
也可以在
$config
数组中用双引号初始化:

$this->email->set_newline("\r\n");
$config = array('newline' => "\r\n");

在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');
    }
}
?>

有关更多详细信息,请参阅适用于我的

。我在xampp windows上运行

我换了一些像这样的部分

php folder go to php.ini find on line 1142 uncomment

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

添加您自己的详细信息

第14行:
smtp\u server=gmail.com主机服务器

第18行:
smtp\u端口=465或587
在第46行和第47行,您需要添加用户名和

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

auth_password= ****** ////change to yours
我改变了gmail设置,因为我使用gmail

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

如果仍要允许访问,请执行以下步骤:

  • 转到我的帐户中的“不太安全的应用”部分
  • 在“访问不太安全的应用程序”旁,选择“打开” (谷歌应用程序用户注意:如果管理员锁定了不太安全的应用程序帐户访问,则此设置将隐藏。)


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

    是否有任何方法可以在配置中散列或隐藏我的smtp密码。我们确实不想使用纯文本密码。
    sendmail_path = "\"C:\Xampp\sendmail\sendmail.exe\" -t"
    sendmail folder: sendmail.ini file
    
    passwordauth_username= ***@***.com //change to yours
    
    auth_password= ****** ////change to yours