2012-11-20 40 views
2

我看過很多帖子涉及到這個問題,SMTP Gmail的錯誤,我做給,但總是得到同樣的錯誤指令..與笨2.1.3

我想用代碼點火器2.1發送SMTP的Gmail。 3,這是代碼:

class Email extends CI_Controller{ 

function index(){ 

$config = Array(
'protocol'  => 'smtp', 
'smtp_crypto' => 'ssl', 
'smtp_host'  => 'smtp.gmail.com', 
'smtp_user'  => '[email protected]', 
'smtp_pass'  => '***********', 
'smtp_port'  => 25, 
'mailtype'  => 'text', 
'smtp_timeout' => 15, 
'charset'  => 'iso-8859-1' 
); 
$this->load->library('email', $config); 

$this->email->set_crlf("\r\n"); 
$this->email->set_newline("\r\n"); 
$this->email->from("[email protected]", "myName"); 
$this->email->to("[email protected]"); 
$this->email->subject("Email Test"); 
$this->email->message("This is email test"); 

if($this->email->send()){ 
    echo 'Email Send'; 
    } else{ 
     show_error($this->email->print_debugger()); 
    } 
} 

,總是錯誤這樣,

Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) 

請幫我修復這個錯誤,謝謝:)

+0

如果我的回答對你有幫助plz接受它作爲答案。 –

回答

2

您需要在服務器配置中啓用php.ini文件中的ssl,並且如果您使用Xampp服務器,則可以檢查它是否已啓用。在那去PHP信息搜索ssl .........

你需要刪除;在extension = php_openssl.dll這行之前在php.ini文件中。

您需要啓用OpenSSL的........

我遇到這個錯誤recently.There是在代碼中的一個小錯誤........

function sendMail() 
{ 
    $config = Array(
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://smtp.googlemail.com', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', // change it to yours 
    'smtp_pass' => 'xxx', // change it to yours 
    'mailtype' => 'html', 
    'charset' => 'iso-8859-1', 
    'wordwrap' => TRUE 
); 

     $message = $this->load->view('upload_success','',TRUE); 
     $this->load->library('email', $config); 
     $this->email->set_newline("\r\n"); 
     $this->email->from('[email protected]'); // change it to yours 
     $this->email->to('[email protected]');// change it to yours 
     $this->email->subject('Resume from JobsBuddy for your Job posting'); 
     $this->email->message($message); 
     if($this->email->send()) 
    { 
     echo 'Email sent.'; 
    } 
    else 
    { 
    show_error($this->email->print_debugger()); 
    } 

} 

這是一個工作代碼,我使用後,我解決了你所面臨的問題.....

+0

我試過了你的代碼,但是有同樣的錯誤,我已經在我的php.ini上啓用了開放的ssl擴展.. –

+0

你怎麼能說你啓用了你的openssl啓用。你有證據嗎?檢查本地主機。 PHP信息標籤搜索openssl。你會發現啓用。 –

+0

我檢查過phpinfo,opensll支持已啓用,我正在使用wamp服務器。 –