<?php
        // Check if User Coming From A Request
        if ($_SERVER['REQUEST_METHOD'] == 'POST')
        {
            // Assign Variables
            $form_name = filter_var($_POST['form_name'], FILTER_SANITIZE_STRING);
            $form_email = filter_var($_POST['form_email'], FILTER_SANITIZE_EMAIL);
            $form_phone = filter_var($_POST['form_phone'], FILTER_SANITIZE_NUMBER_INT);
            $form_subject  = filter_var($_POST['form_subject'], FILTER_SANITIZE_STRING);
            $form_message  = filter_var($_POST['form_message'], FILTER_SANITIZE_STRING);
            // Creating Array of Errors
            $formErrors = array();
            if (strlen($form_name) <= 3) {
                $formErrors[] = 'Le nom d\'utilisateur doit être plus grand que <strong>3</strong> caractères';
            }
            if (strlen($form_subject) <= 3) {
                $formErrors[] = 'Sujet ne peut pas être inférieur à <strong>10</strong> caractères';
            }
            if (strlen($form_message) <= 10) {
                $formErrors[] = 'Le message ne peut pas être inférieur à <strong>10</strong> caractères';
            }
            $headers = "From: ydaoud@galaxysolutions.ma\r\n";

            $headers .= "Reply-To: ydaoud@galaxysolutions.ma\r\n";

            $headers .= "Return-Path: ydaoud@galaxysolutions.ma\r\n";

            $headers .= "CC: ydaoud@galaxysolutions.ma\r\n";
            if (empty($formErrors)) {

            $to = "ydaoud@galaxysolutions.ma";

            $message = "Les information Contacter"   . "\n".
                       "Nom est: "               .$form_name    . "\n".
                       "Email est:  "            .$form_email   . "\n".
                       "Téléphone est: "         .$form_phone;
            $subject = "Envoyez Votre Message :" . $form_subject;

            $msg="Bonjour"." ". $form_name . "\n\n" ."Nous vous remercions pour votre interét et votre Confiance." . "\n\n"
                . "Votre Inscription sur Galaxy Solutions a bien été enregistrée" ."\n\n"
                ."Nous vous rappelons vos identifiants de connexion utilisateur :" .$form_email ."\n\n\n\n\n\n"."Cordialement."."\n\n"."l'equipe GALAXY SOLUTIONS";

            $from="contact@galaxysolutions.ma";

            mail($to,$subject,$message, 'From: '. $form_email );

            mail($form_email,$subject,$msg, 'From: '. $from );

                $form_name='';
                $form_email='';
                $form_phone='';
                $form_subject='';
                $form_message='';

                $success = '
                    <div class="alert alert-success alert-dismissible" role="start">
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        vos informations ont été envoyées avec succès
                    </div>';

            }

        }
?>

<?php
require_once 'navbar/header.php';
?>

<div class="inner-banner text-center">
    <div class="container">
        <div class="box">
            <h3>Contact</h3>
        </div><!-- /.box -->
    </div><!-- /.container -->
</div>


<section class="contact_us">
    <div class="container">
        <div class="row">
            <div class="col-md-6 col-sm-12 col-xs-12">
                <div class="section-title">
                    <h3>Envoyez votre Message</h3>
                </div>
                <div class="default-form-area">
                    <form id="contact-form" name="contact_form" class="default-form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" autocomplete="on">
                          <?php if (! empty($formErrors)) { ?>
                        <div class="alert alert-danger alert-dismissible" role="start">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                            <?php
                                foreach($formErrors as $error) {
                                    echo $error . '<br/>';
                                }
                            ?>
                        </div>
                        <?php } ?>
                        <?php if (isset($success)) { echo $success; } ?>
                        <div class="row clearfix">
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <div class="form-group">
                                    <input type="text" name="form_name" class="form-control"  placeholder="Entrer votre nom *" required="">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <div class="form-group">
                                    <input type="email" name="form_email" class="form-control required email"  placeholder="Email *" required="">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <div class="form-group">
                                    <input type="text" name="form_phone" class="form-control" placeholder="Entrer votre telephone">
                                </div>
                            </div>
                            <div class="col-md-6 col-sm-6 col-xs-12">
                                <div class="form-group">
                                    <input type="text" name="form_subject" class="form-control"  placeholder="Entrer votre Sujet*">
                                </div>
                            </div>
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div class="form-group">
                                    <textarea name="form_message" class="form-control textarea required" placeholder="Entrer votre Message"></textarea>
                                </div>
                            </div>
                            <div class="col-md-12 col-sm-12 col-xs-12">
                                <div class="form-group">
                                    <button class="thm-btn2" name="submit_contact" type="submit">Envoyer Message</button>
                                </div>
                            </div>

                        </div>
                    </form>
                </div>
            </div>
            <div class="google_maps col-md-6">
                <iframe class="iframe-google-maps" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3322.650083496031!2d-7.124410685505946!3d33.614382448125696!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xda7aae9d3c9c201%3A0x2b233b04995f2261!2sGalaxy+Solutions+SARL!5e0!3m2!1sfr!2sma!4v1542993303618" width="550" height="450" frameborder="0" style="border:0" allowfullscreen>
                </iframe>
            </div>
        </div>
    </div>
</section>

<section class="contact_details sec-padd2">
    <div class="container">
        <div class="row">
            <div class="col-md-4 col-sm-6 col-xs-12">
                <div class="item center">
                    <div class="icon_box">
                        <span class="icon-magnifying-glass"></span>
                    </div>
                    <h4>Rendez-nous Visite</h4>
                    <div class="text">
                        <p>Rue Pasteur N° 15 BENSLIMANE </p>
                    </div>
                </div>
            </div>
            <div class="col-md-4 col-sm-6 col-xs-12">
                <div class="item center">
                    <div class="icon_box">
                        <span class="icon-clock"></span>
                    </div>
                    <h4>Horaire  Bureau</h4>
                    <div class="text">
                        <p>Lundi jusqu'au Vendredi: 08:30 - 18.00 <br/>Samedi : 09:00 - 12:00</p>
                    </div>
                </div>
            </div>
            <div class="col-md-4 col-sm-6 col-xs-12">
                <div class="item center">
                    <div class="icon_box">
                        <span class="icon-telephone"></span>
                    </div>
                    <h4>Contact</h4>
                    <div class="text">
                        <p>Téléphone: 0523294119 <br>Email: contact@galaxysolution.ma</p>
                    </div>
                </div>
            </div>
        </div>

    </div>
</section>

<?php
require_once 'navbar/footer.php'
?>


