Sending email with Codeigniter using Gmail

Asked

Viewed 874 times

1

I am trying to make a form to send email 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 is 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 */

Usage Ubuntu 14.04, Nginx, phpfpm operating system.

If anyone can help, I’d appreciate it.

  • you are using local server?

  • this, local server

  • then you will need to configure the local server for sending emails, from a searched in sendmail which is a good tool for this

1 answer

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.