Sending mail with Codeigniter using Gmail

0

I'm trying to make a form for sending emails but I get the following error:

A PHP Error was encountered

Severity: Warning

Message: fsockopen(): unable to connect to ssl://smtp.googlemail.com:465 (Connection timed out)

I created a configuration file in the application / config folder called email.php with the following code:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| EMAIL CONFING
| -------------------------------------------------------------------
| Configuration of outgoing mail server.
| */
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='465';
$config['smtp_timeout']='30';
$config['smtp_user']='[email protected]';
$config['smtp_pass']='password';
$config['charset']='utf-8';
$config['newline']="\r\n";

/* End of file email.php */
/* Location: ./system/application/config/email.php */

And my controller looks like this:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Email extends CI_Controller {

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

    public function index()
    {
            #pega os dados enviado via post
            $contato = $this->input->post('contato');
            $email = $this->input->post('email');
            $mensagem = $this->input->post('mensagem');

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

            #envio do e-mail
            $this->email->from('[email protected]');
            $this->email->to('[email protected]');
            $this->email->subject('Dúvida enviada através do site');
            $this->email->message('Email resposta: '.$email.'<br /> Mensagem:<br />'.$mensagem);
            if($this->email->send()){
                echo 'E-mail enviado';
            } else {
                show_error($this->email->print_debugger());
            }
    }

}

/* End of file Email.php */
/* Location: ./application/controllers/Email.php */

I use Ubuntu operating system 14.04, nginx, phpfpm.

If anyone can help, thank you right away.

    
asked by anonymous 26.05.2015 / 21:41

1 answer

1

Verify that the email settings for your php.ini are enabled to send email via ssl by removing the comment from the following statement:

extension=php_openssl.so

link

    
31.05.2015 / 16:40