61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**Mail_model ls augustus 2024 */
|
|
|
|
class Mail_model extends MY_Model{
|
|
|
|
|
|
// protected $tablename = "tb_users";
|
|
// public $gID;
|
|
|
|
function __construct(){
|
|
parent::__construct();
|
|
$models = array();
|
|
$this->load->model($models);
|
|
}
|
|
|
|
function sendTheEmail( $to, $subject, $html, $cc = FALSE){
|
|
$this->load->library( 'email' );
|
|
|
|
$result = "Success";
|
|
|
|
if ( ! is_array( $to ) ) $to = (array) $to;
|
|
|
|
foreach ( $to as $receiver ){
|
|
|
|
$mailParts = explode( '@', $receiver );
|
|
if (! $mailParts || count($mailParts) < 2) return $result="Er gaat iets fout met e-mail adres ".$receiver;
|
|
|
|
// moet dit gebeuren? $this->setmail();
|
|
|
|
$this->email->to( $receiver );
|
|
$this->email->from( 'info@monpas.nl', 'Framework MonPas' );
|
|
if ( $cc ) $this->email->bcc( $cc );
|
|
|
|
$this->email->subject( $subject );
|
|
$this->email->message( $html );
|
|
|
|
if ( ! $this->email->send() ){
|
|
$result = $this->email->print_debugger();
|
|
};
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function setmail(){
|
|
if ( ENVIRONMENT == 'production' ){
|
|
$config['smtp_host'] = $_ENV['MAILGUN']['HOST'];
|
|
$config['smtp_port'] = $_ENV['MAILGUN']['SMTP_PORT'];
|
|
$config['smtp_user'] = $_ENV['MAILGUN']['SMTP_USER'];
|
|
$config['smtp_pass'] = $_ENV['MAILGUN']['SMTP_PASS'];
|
|
} else {
|
|
$config['smtp_host'] = $_ENV['MAIL']['HOST'];
|
|
$config['smtp_port'] = $_ENV['MAIL']['SMTP_PORT'];
|
|
$config['smtp_user'] = $_ENV['MAIL']['SMTP_USER'];
|
|
$config['smtp_pass'] = $_ENV['MAIL']['SMTP_PASS'];
|
|
}
|
|
|
|
$this->email->initialize( $config );
|
|
}
|
|
} // model
|