Envío de correo electrónico con gmail smtp con codeigniter biblioteca de correo electrónico


<?php
class Email extends Controller {

    function Email()
    {
        parent::Controller();   
        $this->load->library('email');
    }

    function index()
    {
        $config['protocol']    = 'smtp';
        $config['smtp_host']    = 'ssl://smtp.gmail.com';
        $config['smtp_port']    = '465';
        $config['smtp_timeout'] = '7';
        $config['smtp_user']    = '[email protected]';
        $config['smtp_pass']    = '*******';
        $config['charset']    = 'utf-8';
        $config['newline']    = "\r\n";
        $config['mailtype'] = 'text'; // or html
        $config['validation'] = TRUE; // bool whether to validate email or not      

        $this->email->initialize($config);

        $this->email->from('[email protected]', 'myname');
        $this->email->to('[email protected]'); 

        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');  

        $this->email->send();

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

        $this->load->view('email_view');
    }
}

Estoy recibiendo este error:

A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out)
Filename: libraries/Email.php
Line Number: 1641

Usando PORT 25/587

Tengo este error:

A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:func(119):reason(252)
Filename: libraries/Email.php
Line Number: 1641

No quiero usar phpmailer ahora. (En realidad he intentado usar phpmailer, pero fallé).

¿Cómo resuelvo este problema chicos?

Author: Ijas Ameenudeen, 2009-10-12

8 answers

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => 'xxx',
    'smtp_pass' => 'xxx',
    'mailtype'  => 'html', 
    'charset'   => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");

// Set to, from, message, etc.

$result = $this->email->send();

De los Foros de CodeIgniter

 111
Author: Thorpe Obazee,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-30 12:48:09

Necesita habilitar SSL en su configuración de PHP. Carga php.ini y encuentra una línea con lo siguiente:

;extension=php_openssl.dll

Quita el comentario. : D

(eliminando el punto y coma de la instrucción)

extension=php_openssl.dll

 18
Author: Cerebro,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-12 04:39:02

Según los documentos de CI (CodeIgniter Email Library)...

Si prefiere no establecer preferencias utilizando el método anterior, puede en su lugar ponerlos en un archivo de configuración. Simplemente crea un nuevo archivo llamado correo.php, agregue la matriz conf config en ese archivo. A continuación, guarde el archivo en config / email.php y se utilizará automáticamente. NO necesita usar la función initi this->email->initialize () si guarda su preferencias en un archivo de configuración.

I fue capaz de hacer que esto funcione poniendo todas las configuraciones en application/config/email.php .

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Entonces, en uno de los métodos del controlador tengo algo como:

$this->load->library('email'); // Note: no $config param needed
$this->email->from('[email protected]', '[email protected]');
$this->email->to('[email protected]');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();

También, como Cerebro escribió, tuve que descomentar esta línea en mi php.archivo ini y reiniciar PHP:

extension=php_openssl.dll
 13
Author: Luke,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-11 21:46:29

Cámbielo a lo siguiente:

$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "[email protected]"; 
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

$ci->email->from('[email protected]', 'Blabla');
$list = array('[email protected]');
$ci->email->to($list);
$this->email->reply_to('[email protected]', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
 7
Author: RobinCominotto,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-01-23 21:52:57

Enviar correo electrónico html a través de codeiginater

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



    $this->email->clear();
    $config['mailtype'] = "html";
    $this->email->initialize($config);
    $this->email->set_newline("\r\n");
    $this->email->from('[email protected]', 'Website');
    $list = array('[email protected]', '[email protected]');
    $this->email->to($list);
    $data = array();
    $htmlMessage = $this->parser->parse('messages/email', $data, true);
    $this->email->subject('This is an email test');
    $this->email->message($htmlMessage);



    if ($this->email->send()) {
        echo 'Your email was sent, thanks chamil.';
    } else {
        show_error($this->email->print_debugger());
    }
 4
Author: Chamil Sanjeewa,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-23 15:49:25

Otra opción que tengo trabajando, en un servidor linux con Postfix:

Primero, configure CI email para usar el sistema de correo electrónico de su servidor: por ejemplo, en email.php, por ejemplo

# alias to postfix in a typical Postfix server
$config['protocol'] = 'sendmail'; 
$config['mailpath'] = '/usr/sbin/sendmail'; 

Luego configure su postfix para transmitir el correo a Google (tal vez dependiendo de la dirección del remitente). Probablemente tendrá que poner su configuración de usuario-contraseña en /etc/postfix/sasl_passwd (docs)

Esto es mucho más simple (y menos fragmentado) si tiene una caja de Linux, ya configurada para enviar algunos / todos sus salientes correos electrónicos a Google.

 1
Author: leonbloy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-05-02 17:38:29

Tal vez su servidor de alojamiento y servidor de correo electrónico se encuentran en el mismo lugar y no es necesario ir para la autenticación smtp. Simplemente mantenga cada cosa por defecto como:

$config = array(        
    'protocol' => '',
    'smtp_host' => '',
    'smtp_port' => '',
    'smtp_user' => '[email protected]',
    'smtp_pass' => '**********'
    );

O

$config['protocol'] = '';
$config['smtp_host'] = '';
$config['smtp_port'] = ;
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'password';

Funciona para mí.

 1
Author: Shiplu,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-05-07 15:14:28

Puede ser esto:

Si está utilizando cpanel para su sitio web, las restricciones smtp son un problema y causar este error. Restricciones SMTP

Error al enviar un correo electrónico con CodeIgniter

 1
Author: Adrian P.,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:34:47