2012-05-14 113 views
4

我正在学习使用gmail发送邮件的教程,但是我得到的是一个只是挂起的页面,甚至没有加载错误。我使用MAMP,这可能是它不工作的原因。通过gmail发送邮件到CodeIgniter

class Email extends CI_Controller{ 

    public function __construct() 
    { 
     parent::__construct(); 

    } 

    function index(){ 

     $config = Array(
      'protocol' => 'smtp', 
      'smtp_host' => 'ssl://smtp.googlemail.com', 
      'smtp_port' => 465, 
      'smtp_user' => 'email', 
      'smtp_pass' => 'pass' 
     ); 

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

     $this->email->set_newline("/r/n"); 
     $this->email->from('email', 'George'); 
     $this->email->to('email'); 
     $this->email->subject('hey this is an email'); 
     $this->email->message('this is the content of the email'); 

     if($this->email->send()){ 

       echo 'Your message was sent'; 

     }else{ 

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

     } 

    } 



} 

回答

7
在php.ini文件中取消注释延长= php_openssl.dll

$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', config); 
    $this->email->from('[email protected]', 'George'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('hey this is an email'); 
    $this->email->message('this is the content of the email'); 
    $this->email->send(); 
    echo $this->email->print_debugger(); 

希望

这将工作

+1

我没有在我的php.ini这一行,但是你提供的代码似乎工作。我想我需要添加starttls参数。 – Adam

+0

试过这个,它工作。缩小范围,在我的电子邮件配置中添加'$ config ['newline'] =“\ r \ n”'为我解决了这个问题。 –

0

线造成的问题是:

$this->email->set_newline("/r/n"); 

删除它,并尝试发送邮件。

+0

不,它仍然挂起。有什么我需要在Gmail中设置? – Adam

+0

你在Gmail中启用了远程SMTP吗? – gorelative

+0

是启用pop和imap。同时,之间有什么smtp.gmail.com和SSL的区别://smtp.googlemail.com – Adam

0

我只是做了这个成功的自己,但通过配置发送的所有值/ email.php代替。这部分应该不重要。

基本上你是想通过@gmail帐户或你自己的域名发送?如果你试图去通过自己的域名,您需要将DNS更改有关谷歌设置:

Create MX Records

-1

通过使用标准的SMTP端口,并确保使用下面的配置,工程发布开始:

功能指数(){

$配置=阵列( '协议'=> 'SMTP', 'smtp_host'=> 'smtp.googlemail.com', 'SMTP_PORT'=> 25, 'smtp_user'=>'email', 'smtp_pass'=>'pass' );

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

$ this-> email-> from('email','George'); $ this-> email-> to('email'); $ this-> email-> subject('hey this is an email'); $ this-> email-> message('这是电子邮件的内容');

$ this-> email-> send(); }

一旦你已经试过了,这一切都已经工作一个通过这个阅读:

http://codeigniter.com/forums/viewthread/84689/

0

MAMP不与OpenSSL的扩展发货,但你可以自己创建它。详情请参阅this教程