<?php
/**
 * Created by PhpStorm.
 * User: alphonse
 * Date: 1/30/2017
 * Time: 9:21 AM
 */

namespace App\Tools;


use Carbon\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class EmailAlert
{
    public static function insertError($file, $errorMsg, $line=null) {
        try {
            DB::insert('insert into `error_alert` (`date`, `file`, `errorMsg`, `line`)
            values (?, ?, ?, ?)', [date('Y-m-d H:i:s'), $file, $errorMsg, $line]);
        }
        catch (\Throwable $re) {

        }
    }

    public static function sendEmergencyMsg($file, $msg) {
        $html = '<h3 style="color: red">MTN MESSENGER Emergency!!!</h3><hr />';
        $html .= '<b><u>Date</u>: '.Carbon::now()->toDateTimeString().'</b><br />';
        $html .= '<b><u>Source</u>: '.$file.'</b><br /><br />';
        $html .= '<div style="color:red">'.$msg.'</div>';

//        Mail::send('emails.alert', ['html'=>$html], function ($m) {
//            $m_email = 'support@npontu.com';
//            $m->from($m_email, 'MESSENGER Alert');
//            $m->to('appengineer@npontu.com', 'Dev Team');
//            $m->cc('npontualph@gmail.com', 'Alphonse Malan');
//            $m->subject('MTN MESSENGER - Emergency!!');
//        });
    }
}