<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

function Send_mail_to_user($email,$message,$subject)
{
    $CI = &get_instance();
    
    $CI->load->library('email');

    if (base_url() == 'http://localhost:80/perfex_crm/' || base_url() == 'http://localhost/perfex_crm/') {
        $config = array(
            'protocol' => 'smtp',
            'smtp_host' => 'smtp.sendgrid.net',
            'smtp_port' => 465,
            'smtp_user' => 'apikey',
            'smtp_pass' => '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',
            'crlf' => "\r\n",
            'newline' => "\r\n",
        );
        $CI->email->initialize($config);
        $CI->email->from('no-reply@legaldirect.ca', 'Legal Direct');
        $CI->email->to($email);
        $CI->email->subject($subject);
        $CI->email->message($message);
        if ($CI->email->send()) {
            return true;
        } else {
            return false;
        }
    }else{
        $config = Array(
            'protocol' => 'smtp',
            'smtp_host' => 'sandbox.smtp.mailtrap.io',
            'smtp_port' => 2525,
            'smtp_user' => '3e97e9c258c86d',
            'smtp_pass' => '96ab96cf9461e9',
            'crlf' => "\r\n",
            'newline' => "\r\n"
          );
        $CI->email->initialize($config);
        $CI->email->from('no-reply@legaldirect.ca', 'Legal Direct');
        $CI->email->to($email);
        $CI->email->subject($subject);
        $CI->email->message($message);
        if ($CI->email->send()) {
            return true;
        } else {
           return false;
        }
    }
}
