2015-10-15 2 views
1

Я отправляю электронное письмо с использованием codeigniter Version 2.2.1. Но это дает мне ошибку. Пожалуйста, скажи мне почему ? Вот мой PHP-код.Почему отправка электронной почты не работает в codeigniter?

 $config = array(
      'protocol'=>'smtp', 
      'smtp_host'=>'ssl://smtp.googlemail.com', 
      'smtp_port'=>465, 
      'smtp_user'=>'[email protected]', 
      'smtp_pass'=>'xxx' 
     ); 

     $this->load->library('email',$config); 

     $this->email->set_newline("\r\n"); 
     $this->email->from('[email protected]', "My Name"); 
     $this->email->to($to); 
     $this->email->subject($subject); 
     $this->email->message($message); 
     $this->email->send(); 
     return $this->email->print_debugger(); 

Но когда я отправлю. Это дает мне эту ошибку. Почему? Я пробовал много способов. Но не работает. Зачем ?

220 smtp.gmail.com ESMTP ci2sm13227458pbc.66 - gsmtp 

hello: 250-smtp.gmail.com at your service, [61.4.76.240] 
250-SIZE 35882577 
250-8BITMIME 
250-STARTTLS 
250-ENHANCEDSTATUSCODES 
250-PIPELINING 
250-CHUNKING 
250 SMTPUTF8 

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

from: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

to: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

data: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. ci2sm13227458pbc.66 - gsmtp 
502 5.5.1 Unrecognized command. ci2sm13227458pbc.66 - gsmtp 
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. ci2sm13227458pbc.66 - gsmtp 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. 

User-Agent: CodeIgniter 
Date: Thu, 15 Oct 2015 08:45:28 +0200 
From: "War" <[email protected]> 
Return-Path: <[email protected]> 
To: [email protected] 
Subject: =?utf-8?Q?subject?= 
Reply-To: "[email protected]" <[email protected]> 
X-Sender: [email protected] 
X-Mailer: CodeIgniter 
X-Priority: 3 (Normal) 
Message-ID: <[email protected]> 
Mime-Version: 1.0 


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

Every find bro ? I am here for u . 

Я использую Localhost на XAMPP. Так что мне нужно что-то настроить в , пожалуйста, мой localhost?

+0

Сбой при его завершении, означает неправильное имя пользователя или пароль –

+0

Извините. Добавлено неправильное сообщение об ошибке. Теперь я его отредактировал. Так что, пожалуйста, в чем проблема? –

+0

ваша команда startTLS не выполняется, что означает, что TLS PORTS либо отключены, либо они не добавлены в брандмауэр –

ответ

0

Спасибо, что помогли мне. Наконец я получил ответ. Проблема была в Google. Это блокирует менее безопасные приложения. Поэтому я просто перешел к этому URL-адресу https://www.google.com/settings/security/lesssecureapps после входа в Google и включил доступ для менее безопасных приложений. Здесь вы можете узнать больше.

0

Попробуйте

public function sendEmail(){ 
    //now copy and paste the below code 
    $this->load->library('email'); 
    $html = "Test email"; 
    $email_setting = array('mailtype'=>'html'); 
    $this->email->initialize($email_setting); 
    $this->email->from('Test'); 
    $this->email->to('the email address'); 
    $this->email->subject('Title': 'New email'); 
    $this->email->message($html); 
    $this->email->send(); 
} 

Позвольте мне знать, если эта работа. вы можете изменить свой код позже. Подробнее о том, как отправить электронное письмо в codeigniter, попробуйте эту ссылку http://w3code.in/2015/09/how-to-send-email-using-codeigniter/

+0

Остальные $ email_setting будут такими же, как моя $ config? –

+0

Да, вы можете использовать любой из – Ricky

+0

. Сначала попробуйте запустить мой код и проверьте, работает ли он, вы можете изменить свой код позже на – Ricky

0

Это полностью работающая функция электронной почты, которую я сейчас использую.

public function send_email($to, $subject, $message) 
{ 
    // Initilize email configuration 
    $config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'intsmtp.abc.com.sg', 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
    ); 

    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from('ABCMaster'); 
    $this->email->to($to); 
    $this->email->subject($subject); 
    $this->email->message($message); 

    return ($this->email->send()); // returns TRUE or FALSE 
} 

Вот как я использовал его:

$to = "[email protected]"; 
$subject = "Learning ABCs"; 
$message = "ABCs are very simple. I am using them now.<br>"; 
$message .= "If you would like to learn more, please contact me."; 

// Send email 
if ($this->send_email($to, $subject, $message)) 
{ 
    // Sending email success 
} 
else 
{ 
    // Sending Email has failed 
} 
+0

Это не работает –

+0

Какая ошибка? – hzq

+0

Если это та же ошибка, я предлагаю вам следовать ссылке @ noobie-php suggestion от его комментария к вашему вопросу. – hzq

1

Попробуйте это:

public function some_name() { 

    $email = $this->input->post('email'); 

    $config = Array(
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.googlemail.com', 
     'smtp_port' => 465, 
     'smtp_user' => '*****@gmail.com', 
     'smtp_pass' => '*****', 
     'mailtype' => 'html', 
     'charset' => 'utf-8', 
     'wordwrap' => TRUE 
    );    

    /* 
    * 
    * Send email with #temp_pass as a link 
    * 
    */ 

    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from('****@gmail.com', "****"); 
    $this->email->to($email); 
    $this->email->subject("***********"); 

    $message = "<p>Your Account ************</p>"; 
    $this->email->message($message); 
    $result = $this->email->send(); 

} 
0

Как проверить ваш код со следующими отрывками

$config = array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'mail.google.com', 
    //'smtp_port' => '465', 
    'smtp_timeout' => '7', 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'password', 
    'charset' => 'utf-8', 
    'newline' => "rn", 
    'mailtype' => 'html', // or html 
    'wordwrap' => FALSE, 
    'validation' => TRUE // bool whether to validate email or not 
); 

$this->load->library('email'); 
$this->email->initialize($config); 
$this->email->set_newline("rn"); 
$this->email->from($email, 'Subject'); 
$this->email->to('[email protected],[email protected],[email protected]'); 
$this->email->subject('Contact us form by: ' . $name); 
$this->email->message($message . '<br>website:' . $website); 
$this->email->send(); 

//echo $this->email->print_debugger(); `enter code here` 

Пожалуйста, проверьте код с выше фрагмента. Отлаживайте свой код для почты, используя // echo $this->email->print_debugger();. Если проблема по-прежнему сохраняется, напишите здесь.

Смежные вопросы