<?php

namespace App\Http\Controllers\API;

use App\Http\Controllers\Controller;

use App\Models\User;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Http;
use PHPMailer\PHPMailer\PHPMailer;  
use PHPMailer\PHPMailer\Exception;

use DateTime;

use DatePeriod;

use DateInterval;

use DB;
use Mail;

class SendmailController extends Controller
{
    
    public function problemesignaler_embmission(Request $request)
    {
        
        $name= $request->input('name');
        $email= $request->input('email');
        $sujet= $request->input('sujet');
        $message= $request->input('message');
        
        
        $vrai_expediteur='contact@embmission.com';   
        $expediteur='emb-mission@touszone.com';
        $nom_expediteur='emb-mission';
        $destinataire='contact@embmission.com'; //dieudonneekiki@gmail.com
        
        $subject = $sujet;
        $body = view('mailsignalerprobleme',compact('name','email','sujet','message')); 
        $isHTML = true;
        
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->CharSet = 'utf-8';
        $mail->Host       = 'ruban.o2switch.net';
        $mail->SMTPDebug  = 0;
        $mail->SMTPAuth   = true; //true
        $mail->Port       = 465;
        $mail->Username   = 'emb-mission@touszone.com';
        $mail->Password   = 'NQVCXncuqm8!';
        $mail->DKIM_selector = 'phpmailer';
        
        $mail->setFrom($vrai_expediteur, utf8_decode($nom_expediteur));
        $mail->addAddress($destinataire);
        $mail->SMTPSecure = 'ssl';
    
        $mail->isHTML($isHTML);                   
        $mail->Subject = $subject;
        $mail->Body    = $body;
        $mail->send();
        
        return response()->json(['statutmail' => 'success']);
        
    } 
    
    public function contact_apropos(Request $request)
    {
        
        $name= $request->input('name');
        $email= $request->input('email');
        $sujet= $request->input('sujet');
        $message= $request->input('message');
        
        
        $vrai_expediteur='contact@embmission.com';   
        $expediteur='emb-mission@touszone.com';
        $nom_expediteur='emb-mission';
        $destinataire='contact@embmission.com'; //dieudonneekiki@gmail.com
        
        $subject = $sujet;
        $body = view('mailcontactapropos',compact('name','email','sujet','message')); 
        $isHTML = true;
        
        $mail = new PHPMailer();
        $mail->IsSMTP();
        $mail->CharSet = 'utf-8';
        $mail->Host       = 'ruban.o2switch.net';
        $mail->SMTPDebug  = 0;
        $mail->SMTPAuth   = true; //true
        $mail->Port       = 465;
        $mail->Username   = 'emb-mission@touszone.com';
        $mail->Password   = 'NQVCXncuqm8!';
        $mail->DKIM_selector = 'phpmailer';
        
        $mail->setFrom($vrai_expediteur, utf8_decode($nom_expediteur));
        $mail->addAddress($destinataire);
        $mail->SMTPSecure = 'ssl';
    
        $mail->isHTML($isHTML);                   
        $mail->Subject = $subject;
        $mail->Body    = $body;
        $mail->send();
        
        return response()->json(['statutmail' => 'success']);
        
    } 
        
}
