2012-03-05 206 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()); 
     } 
    } 
} 

?> 
相关问题