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(); を使用する場合 Fatal error: Call to undefined method CI_Controller::CI_Controller() in C:\wamp\www\test\application\controllers\email.php on line 6 私はphp 5.4.3を使用していますが

ここで何が欠けているか教えてください。

4

2 に答える 2

1

組み込みのMailクラスは、キー名smtp_usersmtp_passsmtp 資格情報を使用します。

配列内のusernameおよびpasswordパラメータをおよびに変更します。$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 に答える