<?php

class Email_model extends CI_Model {

	/**
	 * Si el email no funciona se debe activar el uso de aplicaciones poco seguras en gmail:
	 * https://support.google.com/accounts/answer/6010255?p=lsa_blocked&hl=es&visit_id=637452213777025774-1883282455&rd=1
	 */

	public function send_email($to, $subject, $message){
		$this->load->library('email');
		
		/*
		// SOLO DESSARROLLO
		if(ENVIRONMENT == 'development') {
			$config['protocol']     = 'smtp';
			$config['smtp_host']    = 'ssl://smtp.gmail.com';
			$config['smtp_port']    = '465';
			$config['smtp_timeout'] = '7';
			$config['smtp_user']    = 'tiendadementegames@gmail.com';
			$config['smtp_pass']    = 'Dmnt0303';
			$config['charset']      = 'utf-8';
			$config['newline']      = "\r\n";
			$config['mailtype']     = 'html';
			$config['validation']   = TRUE;
			$this->email->initialize($config);
		}
		*/

		$this->email->set_mailtype("html");
		$this->email->from('contacto@dementegames.cl', 'DeMente Games');
		$this->email->to($to);
		$this->email->subject($subject);

		$this->email->message($message);
		$result = $this->email->send();
		return $result;
	}
}