2

我在这个网站和许多其他网站上看到了同样的问题,但他们提供的解决方案对我不起作用。所以我又问了。

要发送邮件,我编写了以下代码

<?php

class Email extends CI_Controller{
function __construct()
{
    parent::__construct();
}

function index()
{
    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'username' => 'mymail@gmail.com',
        'password' => 'password' 
    );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");

    $this->email->from('mymail@gmail.com', 'mymail bcc');
    $this->email->to('mymail@gmail.com');
    $this->email->subject('This is a test email');
    $this->email->message('Oops This is Great.');

    if($this->email->send())
    {
        echo 'Your email was sent';       
    }

    else
    {
        show_error($this->email->print_debugger());
    }
       }
       }

我安装了 openssl 并且还取消了 php.ini 中的 extension=php_openssl.dll 行的注释。但我得到以下错误

  An Error Was Encountered

   220 mx.google.com ESMTP qp6sm2730344pbc.55

    hello: 250-mx.google.com at your service, [119.30.39.78]
    250-SIZE 35882577
     250-8BITMIME
     250-AUTH LOGIN PLAIN XOAUTH
     250 ENHANCEDSTATUSCODES

     from: 530-5.5.1 Authentication Required. Learn more at
     530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55

     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 qp6sm2730344pbc.55

     to: 530-5.5.1 Authentication Required. Learn more at
     530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55

     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 qp6sm2730344pbc.55

     data: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 
     http://support.google.com/mail/bin/answer.py?answer=14257 qp6sm2730344pbc.55

     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 qp6sm2730344pbc.55
     502 5.5.1 Unrecognized command. qp6sm2730344pbc.55
     The following SMTP error was encountered: 502 5.5.1 Unrecognized command. qp6sm2730344pbc.55
     Unable to send email using PHP SMTP. Your server might not be configured to send
      mail using this method.

当我使用 parent::CI_Controller(); 我收到一个致命错误致命错误:在第 6 行调用 C:\wamp\www\test\application\controllers\email.php 中未定义的方法 CI_Controller::CI_Controller() 虽然我使用的是 php 5.4.3

请让我知道我在这里缺少什么。

4

2 回答 2

1

内置Mail类使用密钥名称smtp_usersmtp_passsmtp 凭据。

将数组中的usernameandpassword参数更改为and 。$configsmtp_usersmtp_pass

于 2012-08-12T12:31:26.080 回答
0

工作代码

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/* SENDS EMAIL WITH GMAIL */

class Email extends CI_Controller {


    function __construct()
    {
        parent::__construct();
        //Do your magic here
    }

    function index()
    {
        $config = array(
            'protocol'  => 'smtp',
            'smtp_host' => 'ssl://smtp.gmail.com',
            'smtp_port' => 465,
            'smtp_user' => 'mygmail@gmail.com',
            'smtp_pass' => '*********'
        );

        $this->load->library('email',$config);
        $this->email->set_newline("\r\n");
        // $this->email->initialize($config);

        $this->email->from('mygmail@gmail.com', 'Chirag');
        $this->email->to('mygmail@gmail.com');
        $this->email->cc('myanothergmail@gmail.com');   
        $this->email->subject('This is an email testing');
        $this->email->message('It\'s working, that\'s really awesome..!');

        if ($this->email->send()) 
        {
            echo "Your Email has been sent successfully... !!";
        }
        else
        {
            show_error( $this->email->print_debugger());
        }
    }

}

/* End of file email.php */
/* Location: ./application/controllers/email.php */
于 2013-04-08T12:22:19.837 回答