<?php

//require './PHPMailerAutoload.php';
require "./PHPMailer_5.2.0/class.phpmailer.php";

$name = $_POST['name'];
$doctor = $_POST['doctor'];
$department = $_POST['department'];
$date = $_POST['date'];
$emailid = $_POST['emailid'];
$feedmessage = $_POST['feedmessage'];

if ($name != "" && $doctor != "" && $department != "" && $date != "") {
    if ($name == "") {
        echo 'Name is empty';
        exit();
    }
    if ($doctor == "") {
        echo 'Doctor is empty';
        exit();
    }
    if ($department == "") {
        echo 'Department is empty';
        exit();
    }
    if ($date == "") {
        echo 'Date is empty';
        exit();
    }

    $output = '<!DOCTYPE html>
                                    <html>
                                    <head>
                                        <title>Appointment form</title>
                                        <meta charset="UTF-8">
                                        <meta name="viewport" content="width=device-width, initial-scale=1.0">
                                    </head>
                                    <body>    
                                    <p>Appointment</p>
                                    <p>Name : ' . $name . '</p>
                                    <p>Doctor : ' . $doctor . '</p>
                                    <p>Department : ' . $department . '</p>
                                    <p>Date : ' . $date . '</p>
                                    </body>
                                </html>';

    /*$toaddress = "suddu.gp@gmail.com";
    $mail = new PHPMailer();
    $mail->isSendmail();
    $mail->Subject = 'Tathagat | Request For Appointment';
    $mail->setFrom('info@tathagathearthospital.com', 'Tathagat');
    $mail->addAddress($toaddress);
    $mail->IsHTML(true);
    $mail->Body = preg_replace('/\[\]/', '', $output);
    $mail->AddCC('developerblrads@gmail.com');*/
    
                $toaddress = "frontoffice@tathagathearthospital.com";    
                $mail = new PHPMailer();
    		    $mail ->IsSmtp();
                $mail->SMTPDebug = 0;
                $mail ->SMTPAuth = true;
    		    //$mail ->SMTPSecure = 'tls';
                $mail->Host = "mail.tathagathearthospital.com";
                $mail->Port = 587;   //587, 25;
    		    $mail ->IsHTML(true);
                $mail->Username = "info@tathagathearthospital.com";
                $mail->Password = "X+%7=mKrvwAs";
                $mail->SetFrom('info@tathagathearthospital.com	', 'Tathagat');
    		   
    		    $mail ->Subject = 'Tathagat | Request For Appointment';
    		    $mail ->Body = preg_replace('/\[\]/', '', $output);
    		    $mail ->AddAddress($toaddress);
                $mail->AddCC('mahanteshrc@tathagathearthospital.com');
                //$mail->AddCC('developerblrads@gmail.com');  
    
    if ($mail->send()) {
        echo 'ok';
        exit(0);
    } else {
        echo $mail->ErrorInfo;
        //echo 'Sorry.. Please try again later..';
        exit(0);
    }
} else {
    if ($name != "" && $emailid != "" && $department != "" && $feedmessage != "") {
        if ($name == "") {
            echo 'Name is empty';
            exit();
        }
        if ($emailid == "") {
            echo 'Email is empty';
            exit();
        }
        if ($department == "") {
            echo 'Department is empty';
            exit();
        }
        if ($feedmessage == "") {
            echo 'Message is empty';
            exit();
        }

        $output = '<!DOCTYPE html>
                                    <html>
                                    <head>
                                        <title>Feedback</title>
                                        <meta charset="UTF-8">
                                        <meta name="viewport" content="width=device-width, initial-scale=1.0">
                                    </head>
                                    <body>    
                                    <p>Feedback</p>
                                    <p>Name : ' . $name . '</p>
                                    <p>Email : ' . $emailid . '</p>
                                    <p>Department : ' . $department . '</p>
                                    <p>Message : ' . $feedmessage . '</p>
                                    </body>
                                </html>';

        /*$toaddress = "suddu.gp@gmail.com";
        $mail = new PHPMailer();
        $mail->isSendmail();
        $mail->Subject = "Tathagat | Feedback from $name";
        $mail->setFrom('info@tathagathearthospital.com', 'Tathagat');
        $mail->addAddress($toaddress);
        $mail->IsHTML(true);
        $mail->Body = preg_replace('/\[\]/', '', $output);
        $mail->AddCC('developerblrads@gmail.com');*/
        
                $toaddress = "frontoffice@tathagathearthospital.com";    
                $mail = new PHPMailer();
    		    $mail ->IsSmtp();
                $mail->SMTPDebug = 0;
                $mail ->SMTPAuth = true;
    		    //$mail ->SMTPSecure = 'tls';
                $mail->Host = "mail.tathagathearthospital.com";
                $mail->Port = 587;   //587, 25;
    		    $mail ->IsHTML(true);
                $mail->Username = "info@tathagathearthospital.com";
                $mail->Password = "X+%7=mKrvwAs";
                $mail->SetFrom('info@tathagathearthospital.com	', 'Tathagat');
    		   
    		    $mail ->Subject = 'Tathagat | Feedback from '.$name;
    		    $mail ->Body = preg_replace('/\[\]/', '', $output);
    		    $mail ->AddAddress($toaddress);
                $mail->AddCC('mahanteshrc@tathagathearthospital.com');
                //$mail->AddCC('developerblrads@gmail.com');
        
        if ($mail->send()) {
            echo 'ok';
            exit(0);
        } else {
            echo 'Sorry.. Please try again later..';
            exit(0);
        }
    }
}



