Created
October 12, 2018 12:21
-
-
Save portapipe/6a82b001c69c3798241c3e9109653cf8 to your computer and use it in GitHub Desktop.
Inviare email smtp con Gmail su Codeigniter (config + model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? defined('BASEPATH') OR exit('No direct script access allowed'); | |
$indirizzo_email = "[email protected]"; | |
$password_email = "la_tua_password"; | |
$config['protocol'] = 'smtp'; | |
$config['smtp_host'] = 'smtp.gmail.com'; | |
$config['smtp_port'] = '465'; | |
$config['smtp_crypto'] = 'ssl'; | |
$config['smtp_timeout'] = '30'; | |
$config['smtp_user'] = $indirizzo_email; | |
$config['smtp_pass'] = $password_email; | |
$config['charset'] = 'utf-8'; | |
$config['mailtype'] = 'html'; | |
$config['wordwrap'] = TRUE; | |
//Le righe seguenti sono quelle che solitamente, se assenti, danno timeout in fase di invio | |
$config['newline'] = "\r\n"; | |
$config['crlf'] = "\r\n"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Email_model extends CI_Model { | |
private $nome_mittente = "La Mia Azienda"; | |
public function __construct() | |
{ | |
parent::__construct(); | |
//La configurazione è nella cartella config/email.php | |
$this->load->library("email"); | |
} | |
public function invia($destinatario,$oggetto,$messaggio){ | |
$this->email->from($this->email->smtp_user, $this->nome_mittente); | |
$this->email->to($destinatario); | |
//$this->email->cc('[email protected]'); | |
//$this->email->bcc('[email protected]'); | |
$this->email->subject($oggetto); | |
$this->email->message($messaggio); | |
if(!$this->email->send()){ | |
log_message("error","EMAIL - Errore invio email: ".$this->email->print_debugger()); | |
return false; | |
} | |
return true; | |
} | |
public function staff($oggetto,$messaggio){ | |
$this->invia(array("[email protected]","[email protected]"),$oggetto,$messaggio); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment