Skip to content
Code and Bytes Code and Bytes

Code and Bytes
Code and Bytes

codeigniter

Enviar mensajes desde Codeigniter con gmail

Posted on 28 March, 20159 April, 2020
  1. Descargar Codeigniter
  2. Crear el controlador email  ./application/controllers/email.php con el siguiente código:
    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Email extends CI_Controller {
    
    	public function index()
    	{
    		$config = Array(		
    				    'protocol' => 'smtp',
    				    'smtp_host' => 'ssl://smtp.gmail.com',
    				    'smtp_port' => 465,
    				    'smtp_user' => 'correo@gmail.com',
    				    'smtp_pass' => 'clave',
    				    'smtp_timeout' => '4',
    				    'mailtype'  => 'text', 
    				    'charset'   => 'iso-8859-1'
    				);
     
    		$this->load->library('email', $config);
    		$this->email->set_newline("\r\n");
    
    		$this->email->from('correo@gmail.com', 'correo@gmail.com');
    		$this->email->to('destino@ejemplo.com');
    		//$this->email->cc('otro@otro-ejemplo.com');
    		//$this->email->bcc('copiaoculta@otro-ejemplo.com');
    
    		$this->email->subject('Email Test');
    		$this->email->message('Mensaje de Prueba');
    
    		$this->email->send();
    
    		echo $this->email->print_debugger();
    
    
    	}
    }

  3. Editar el archivo ./application/config/routes.php para que el controlador cargado por defecto sea email
    $route['default_controller'] = "email";
  4. Entramos al index.php y como tenemos cargado por defecto el controlador email éste mostrará este mensaje si todo funciona correctamente:
    220 mx.google.com ESMTP asdfasdfsdf.6 - gsmtp 
    hello: 250-mx.google.com at your service, [190.xxx.xxx.227]
    250-SIZE 35882577
    250-8BITMIME
    250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
    250-ENHANCEDSTATUSCODES
    250-PIPELINING
    250-CHUNKING
    250 SMTPUTF8
    from: 250 2.1.0 OK asdfasdfasd.6 - gsmtp
    to: 250 2.1.5 OK asdfasdfasdf.6 - gsmtp
    data: 354  Go ahead asdfasdfasdf.6 - gsmtp
    250 2.0.0 OK 1427553826 asdfasdfasdf.6 - gsmtp 
    quit: 221 2.0.0 closing connection zf3sm896122vdb.6 - gsmtp
    Your message has been successfully sent using the following protocol: smtp
    User-Agent: CodeIgniter
    Date: Sat, 28 Mar 2015 09:43:25 -0500
    From: "correo@gmail.com" <correo@gmail.com>
    Return-Path: <correo@gmail.com>
    To: destino@otrocorreo.com
    Subject: =?iso-8859-1?Q?Email_Test?=
    Reply-To: "correo@gmail.com" <correo@gmail.com>
    X-Sender: correo@gmail.com
    X-Mailer: CodeIgniter
    X-Priority: 3 (Normal)
    Message-ID: <asdfasdfasd@gmail.com>
    Mime-Version: 1.0
    
    
    Content-Type: text/plain; charset=iso-8859-1
    Content-Transfer-Encoding: 8bit
    
    Mensaje de Prueba.

     

 

PHP codeignitergmailphp

Post navigation

Previous post
Next post

Related Posts

PHP

setlocale no funciona – PHP

Posted on 26 March, 2016

La función setlocale() no funciona al setearlo con el idioma deseado en este caso el español. El primer paso es consultar si se encuentra instalado en el sistema, ingresando en la terminal el comando: locale -a

Read More
PHP

Error 500 Codeigniter .htaccess

Posted on 2 January, 20159 April, 2020

Primero hay que tener habilitado el mod_rewrite y el contenido del archivo htaccess debe ser algo como este ejemplo: RewriteEngine on RewriteCond $1 !^(index\.php|images|fonts|bootstrap-calendar|robots\.txt|css|img|js) RewriteRule ^(.*)$ index.php/$1 [L] y lo mas importante, para evitar el error 500 son los permisos, del archivo index.php el cual debe ser 644    

Read More

PHP Warning: file_put_contents(TelegramException.log): failed to open stream: Permission denied in …/vendor/longman/telegram-bot/src/Exception/TelegramException.php on line 24

Posted on 31 January, 20169 April, 2020

Luego de revisar la línea 24 del archivo al que hace referencia, se puede observar que trata de escribir y añadir un log. namespace Longman\TelegramBot\Exception; class TelegramException extends \Exception { public function __construct($message, $code = 0) { parent::__construct($message, $code); $path = ‘TelegramException.log’; $status = file_put_contents( $path, date(‘Y-m-d H:i:s’, time()) .’…

Read More

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Buscar

Categorias

  • AI (2)
  • Asterisk (9)
  • Bases de datos (1)
  • DevOps (4)
  • Git (2)
  • HTML (1)
  • Laravel (6)
  • Linux (67)
  • MCP Server (1)
  • Mikrotik (3)
  • MySQL (5)
  • n8n (1)
  • Personal (4)
  • PHP (15)
  • Python (2)
  • Software recomendado (1)
  • Tips (1)
  • VSCode (4)
  • vTiger (4)
  • Windows (10)
  • Wordpress (4)
©2026 Code and Bytes | WordPress Theme by SuperbThemes