<?php

require "PHPMailer/PHPMailer/PHPMailerAutoload.php";

$siteKey = '6LfoF30nAAAAAI6cuLEegEvzQoWRcOgexMR2O90V';
$secretKey = '6LfoF30nAAAAAHndOMXvU_632pTrOTLdV_4hJYCy';

$name=$_POST['name'];  
$email=$_POST['email'];
$mobile=$_POST['mobile'];
$csubject=$_POST['subject'];
$message=$_POST['message'];

// Validate reCAPTCHA box
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {

    // Verify the reCAPTCHA response
    $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretKey . '&response=' . $_POST['g-recaptcha-response']);

    // Decode json data
    $responseData = json_decode($verifyResponse);

    // If reCAPTCHA response is valid
    if ($responseData->success) {

        //mail
        $from = "tester@clouddreams.in";
        $subject = "evsaccountingsolutions Form Contact Form";

        $mailcontent = '<table width=100% border=0 border-color:none cellspacing=3 cellpadding=3 class=text style="font-family:Arial; line-height:160% word-spacing:0.4em font-size:14px; border: 1px solid" bgcolor="#F9F9F9" color:"#465864">
        <tr >
        <td colspan="4"  align="center" bgcolor="#e0e1e1" ><strong >Contact Details From ' . $name . '</strong></td>
        </tr>

        <tr><td>First Name</td><td>:</td><td >'.$name.'</td></tr> 
        <tr><td>Email Id</td><td>:</td><td>'.$email.'</td></tr>
        <tr><td>Mobile No </td><td>:</td><td>'.$mobile.'</td></tr>
        <tr><td>Subject </td><td>:</td><td>'.$csubject.'</td></tr>   
        <tr><td>Message </td><td>:</td><td>'.$message.'</td></tr>
        </table>';


        $from_name = "evsaccountingsolutions";
        $to = "gnanasekar.clouddreams@gmail.com";

        function smtpmailer($to, $from, $subject, $body)
        {
            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->SMTPAuth = true; 
     
            $mail->SMTPSecure = ''; 
            $mail->Host = 'newdedi.clouddreams.in';
            $mail->Port = 25;  
            $mail->Username = 'tester@clouddreams.in';
            $mail->Password = 'OUHbP$W2$';    
            
            //   $path = "images/".$file_name;
            //   $mail->AddAttachment($path); 
       
            $mail->IsHTML(true);
            $mail->From= $from;
            $mail->FromName="evsaccountingsolutions Form";
            $mail->Sender=$from; 
            $mail->Subject = $subject;
            $mail->Body = $body;
            $mail->AddAddress($to);
            if(!$mail->Send())
            {
                $error ="Your Mail not send but...";
                return $error; 
            }
            else 
            {
                $error = "Thanks You !! Your email is sent.";  
                return $error;
            }
        }

        $error = smtpmailer($to, $from, $subject, $mailcontent);

        if ($error === true) {
            $url = "mail-sent-error.html";
            header("Location: " . $url);
        } else {
            // echo "Error sending email: " . $error;
            $url = "mail-success.html";
            header("Location: " . $url);
        }

    } else {
        $url = "mail-sent-error.html";
        header("Location: " . $url);
    }
} else {
    $url = "mail-sent-error.html";
    header("Location: " . $url);
}
