2015-06-20 171 views
-1

我想使用CodeIgniter的電子郵件庫發送電子郵件。這是我寫的代碼。無法使用CodeIgniter的電子郵件庫發送電子郵件

 $email_config = array(
      'protocol' => 'smtp', 
      'smtp_host' => ' ssl://smtp.gmail.com', 
      'smtp_port' => '465', 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => '**********', 
      'mailtype' => 'html', 
      'newline' => "\r\n", 
      'charset' => 'iso-8859-1', 
      "wordwrap" => true 
     ); 

    $this->CI->load->library('email', $email_config); 
    $this->CI->email->from('[email protected]', 'invoice'); 
    $this->CI->email->to('[email protected]', "User"); 
    $this->CI->email->subject('Invoice'); 
    $this->CI->email->message('Test'); 
    $this->CI->email->send(); 
    echo $this->CI->email->print_debugger(); 

錯誤:這是我得到的錯誤。

The following SMTP error was encountered: 0 php_network_getaddresses: getaddrinfo failed: Name or service not known Unable to send data: AUTH LOGIN Failed to send AUTH LOGIN command. Error: Unable to send data: MAIL FROM: from: The following SMTP error was encountered: Unable to send data: RCPT TO: to: The following SMTP error was encountered: Unable to send data: DATA data: The following SMTP error was encountered: Unable to send data: User-Agent: CodeIgniter Date: Sun, 21 Jun 2015 05:52:56 +0600 From: "invoice" Return-Path: To: [email protected] Subject: =?iso-8859-1?Q?Invoice?= Reply-To: "[email protected]" X-Sender: [email protected] X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <[email protected]> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="B_ALT_5585fcd8c643b" This is a multi-part message in MIME format. Your email application may not support this format. --B_ALT_5585fcd8c643b Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Test --B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Test --B_ALT_5585fcd8c643b-- Unable to send data: .

The following SMTP error was encountered: Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. User-Agent: CodeIgniter Date: Sun, 21 Jun 2015 05:52:56 +0600 From: "invoice" Return-Path: To: [email protected] Subject: =?iso-8859-1?Q?Invoice?= Reply-To: "[email protected]" X-Sender: [email protected] X-Mailer: CodeIgniter X-Priority: 3 (Normal) Message-ID: <[email protected]> Mime-Version: 1.0

Content-Type: multipart/alternative; boundary="B_ALT_5585fcd8c643b"

This is a multi-part message in MIME format. Your email application may not support this format.

--B_ALT_5585fcd8c643b Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit

Test

--B_ALT_5585fcd8c643b Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable

Test

--B_ALT_5585fcd8c643b--

問題:我曾經是能夠發送電子郵件。然後我重新安裝了我的操作系統和燈服務器,現在我不能。我究竟做錯了什麼?

+0

你試過'sendmail'嗎? – Fawzan

+0

爲什麼你建議另一個圖書館? –

+0

我不是要求您使用另一個庫,而不是smtp,請嘗試發送郵件。只需要在配置中更改這些e參數即可。 – Fawzan

回答

2

我在CI中使用sendmail發送電子郵件。在使用發送郵件之前,您必須在CI中進行一些配置。

首先,進入系統/庫/ Email.php並更改以下

class CI_Email { 

    var $useragent  = "CodeIgniter"; 
    var $mailpath  = "/usr/sbin/sendmail"; // Sendmail path 
    var $protocol  = "sendmail"; // mail/sendmail/smtp 
    var $smtp_host  = "mail.blah-blah.com";  // SMTP Server. 


    ..... 
} 

然後我讓發送電子郵件的方法。

public function send_mail($email, $subject, $message){ 
     //$this->load->library('email'); 
     $this->email->from('[email protected]', 'blah-blah.com'); 
     $this->email->to($email); 
     $this->email->subject($subject); 
     $this->email->message($message); 
     $this->email->send(); 

     echo $this->email->print_debugger(); 

    } 

就是這樣。您現在可以使用send_mail方法發送電子郵件。

+1

echo $ this-> email-> print_debugger();'行由於它上面的return語句而永遠不會執行。更好地檢查'send()'調用的成功,然後有條件地'返回'或'print_debugger()'。 –

+1

@e_i_pi我不知道我是怎麼錯過的,謝謝指點。我將編輯。 – Fawzan

相關問題