<?php

namespace App\Http\Controllers;

use App\Mail\NotifyMail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Models\Admin\Pincode; 
use App\Helpers\MailHelper;
 
class SendEmailController extends Controller
{
   public function contact_email(Request $request)
   {
        $validated = $request->validate([
            'name' => 'required',
            'phone' => 'required',
            'service' => 'required',
            'comment' => 'required',
        ]);
        $name = $validated['name'];
        $phone = $validated['phone'];
        $service = $validated['service'];
        $comment = $validated['comment'];
    
        $to = 'hst.jassim@gmail.com';
        $subject = 'Contact Form Submission';
    
        $headers = "From: contact@hawkssolutions.com\r\n";
        $headers .= "Reply-To: hst.jassim@gmail.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=UTF-8\r\n";
    
        $content = "
        <html>
        <body>
        <table width='750' border='0' cellspacing='0' cellpadding='0'>
            <tr>
                <td colspan='3'><strong>Contact Form</strong></td>
            </tr>
            <tr>
                <td width='30%'>Name</td>
                <td width='5%'>:</td>
                <td width='65%'><font color='#FF0000'>$name</font></td>
            </tr>
            <tr>
                <td width='30%'>Phone</td>
                <td width='5%'>:</td>
                <td width='65%'><font color='#FF0000'>$phone</font></td>
            </tr>
            <tr>
                <td width='30%'>Service</td>
                <td width='5%'>:</td>
                <td width='65%'><font color='#FF0000'>$service</font></td>
            </tr>
            <tr>
                <td width='30%'>Message</td>
                <td width='5%'>:</td>
                <td width='65%'><font color='#FF0000'>$comment</font></td>
            </tr>
        </table>
        </body>
        </html>";

        if (mail($to, $subject, $content, $headers)) {
            return back()->with('success', 'Email sent successfully.');
        } else {
            return back()->with('error', 'Failed to send email.');
        }
    }
}