2017-06-08 32 views
1

我想通過Codeigniter電子郵件庫形式發送電子郵件本地主機。以下是我的代碼。在codeigniter郵件發送錯誤

$config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'xxxxxx', 
    ); 
    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 
    $this->email->from('[email protected]'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('Subject'); 
    $this->email->message('Sample message'); 
    if (!$this->email->send()) 
    { 
     show_error($this->email->print_debugger()); 
    } 
    else 
    { 
     echo 'Your e-mail has been sent!'; 
    } 

我收到以下錯誤: -

無法使用電子郵件PHP郵件()。您的服務器可能未配置爲使用此方法發送郵件。 &

嚴重性:警告

消息:電子郵件():無法連接在 「localhost」 的端口25的郵件服務器,驗證您的 「SMTP」 和 「SMTP_PORT」 在php.ini中設置或使用的ini_set()

文件名:庫/ Email.php

行號:1896年

回溯:

文件:d:\ XAMPP \ htdocs中\ AJAX \應用\控制器\ angular_http.php 行:29 功能:發送

文件:d:\ XAMPP \ htdocs中\ AJAX \的index.php 行:315 函數:require_once

回答

0

我想你還沒配置郵件服務器呢。如果您使用XAMPP,那麼您可以輕鬆地從本地主機發送郵件。

例如你可以配置(考慮'C:\ xampp'作爲安裝目錄)C:\ xampp \ php \ php.ini和c:\ xampp \ sendmail \ sendmail.ini讓gmail發送郵件。

在C:\ xampp \ php \ php.ini中找到extension = php_openssl.dll,並從該行的開頭刪除分號以使SSL適用於localhost的gmail。

在php.ini文件中找到[郵件功能],改變

SMTP=smtp.gmail.com 
smtp_port=587 
sendmail_from = [email protected] 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 

現在打開C:\ XAMPP \ sendmail的\ sendmail.ini。替換sendmail.ini所有現有的代碼與下面的代碼

[sendmail] 

smtp_server=smtp.gmail.com 
smtp_port=587 
error_logfile=error.log 
debug_logfile=debug.log 
[email protected] 
auth_password=my-gmail-password 
[email protected] 

首先,確保你的PHP安裝有支持SSL(尋找一個爲「OpenSSL」,在輸出部分的phpinfo())。

你可以在你的php.ini進行以下設置:

ini_set("SMTP","ssl://smtp.gmail.com"); 
ini_set("smtp_port","465"); 

請拿出堆棧您使用在本地主機上,如果你不使用XAMPP或WAMP。

+0

現在使用此設置錯誤消失了,但郵件尚未發送。 –

+0

請檢查端口25是否打開。 –