2012-03-05 148 views
3

我想通過電子郵件類在與Gmail笨發送電子郵件,但我得到以下錯誤:在笨通過電子郵件類發送電子郵件使用Gmail

錯誤:

A PHP Error was encountered
Severity: Warning
Message: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.googlemail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Filename: libraries/Email.php
Line Number: 1553

這是我在全功能控制研究:

function send_mail(){ 
$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.googlemail.com'; 
$config['smtp_port'] = 465; 
$config['smtp_user'] = '[email protected]'; 
$config['smtp_pass'] = 'xxxxxxx'; 

$this->load->library('email', $config); 
$this->email->set_newline("\r\n"); 

$this->email->from('[email protected]', 'Negin Phosphate Shomal'); 
$this->email->to('[email protected]'); 
$this->email->subject('This is an email test'); 
$this->email->message('It is working. Great!'); 

if($this->email->send()) 
{ 
    echo 'Your email was sent, successfully.'; 
} 

else 
{ 
    show_error($this->email->print_debugger()); 
} 
} 

php.ini改變SMTP,因爲這:

SMTP = ssl://smtp.googlemail.com
smtp_port = 25

我該怎麼辦?

對於

+0

我猜SMTP端口應爲465 – 2012-03-05 09:41:52

回答

7

這是爲我工作

$email_config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => '465', 
      'smtp_user' => '[email protected]', 
      'smtp_pass' => 'password', 
      'mailtype' => 'html', 
      'starttls' => true, 
      'newline' => "\r\n" 
     ); 

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

     $this->email->from('[email protected]', 'invoice'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('Invoice'); 
     $this->email->message('Test'); 

     $this->email->send(); 
+1

這是否「STARTTLS」配置參數存在?它沒有在文檔中列出。事實上,我沒有在Codeigniter 2.0的CI_Email類中看到它 – 2013-01-21 13:18:55

+0

現在你提到了,我搜索了但沒有在框架中找到用法 – 2013-01-22 20:26:22

+0

謝謝你,你爲我節省了一些時間。 – Binaryrespawn 2013-10-23 14:31:42

0

你有沒有打開php_openssl

嘗試在您的php.ini文件中取消註釋extension=php_openssl.dll

0

這是爲我工作在localhost:

<?php 
    class Email extends CI_controller 
    { 
     function index() 
     { 

     $this->load->library('email'); 
     $this->load->helper('url'); 
     $this->load->helper('form'); 

     $config= Array(
      'protocol' =>'localhost', 
      'smtp_host' => 'localhost', 
      'smtp_port' => 'localhost', 
      'smtp_user'=> 'root', 
      'smtp_pass' =>'' 
      ); 

     $this->load->library('email','$config'); 
     $this->email->set_newline("\r\n"); 
     $this->email->from('[email protected]','nisha'); 
     $this->email->to('[email protected]'); 
     $this->email->subject('this is email with subject'); 
     $this->email->message('it s working properly'); 

     if($this->email->send()) 
     { 
      echo "your email send"; 
     } 
     else 
     { 
      show_error($this->email->print_debugger()); 
     } 
    } 
} 

?>