联系表格未将电子邮件发送到指定地址

时间:2019-03-18 15:36:13

标签: php html css web

我正在努力获取要发送到电子邮件的网站的联系表格。我相信到目前为止我所拥有的代码应该足够了,但是由于某种原因它才可以正常工作。如果有人可以提供建议和帮助,我将不胜感激。

表单的布局在网站上看起来很花哨,当我单击“提交”时,表单都可以正确运行。请在“重置”框中填写内容。

`

<?php
// Collect the GET Array Values
if(isset($_GET["err"]))
{
    $errDescription = $_GET["err"];
}
else
{
    $errDescription = "";
}

// Collect the POST Array Values.
$error =false;
$errorVal = "";


    if(isset($_POST["name"])) 
    {
        $name = $_POST["name"];
        if($name != "")
        {
            // Do nothing.
        }
        else
        {
            $error = true;
            $errorVal = "Missing name";
        }

    }
    else 
    {
        $name = "";
    }

    if(isset($_POST["email"])) 
    {
        $email = $_POST["email"];
        if($email != "")
        {
            // Do nothing.
        }
        else
        {
            $error = true;
            $errorVal = "Missing Last subject";
        }

    }
    else 
    {
        $email = "";
    }

    if(isset($_POST["tel"])) 
    {
        $tel = $_POST["tel"];
        if($tel != "")
        {
            // Do nothing.
        }
        else
        {
            $error = true;
            $errorVal = "Missing Email";
        }

    }
    else 
    {
        $tel = "";
    }

    if(isset($_POST["address"])) 
    {
        $address = $_POST["address"];
        if($address != "")
        {
            // Do nothing.
        }
        else
        {
            $error = true;
            $errorVal = "Missing Phone Number";
        }

    }
    else 
    {
        $address = "";
    }

        if(isset($_POST["message"])) 
    {
        $message = $_POST["message"];
        if($message != "")
        {
            // Do nothing.
        }
        else
        {
            $error = true;
            $errorVal = "Missing Phone Number";
        }

    }
    else 
    {
        $message = "";
    }


    if($error === true)
    {
        header("location:contact.php?err=$errorVal");
    }
    else
    {

    }
?>
<!DOCTYPE html>
<html lang="en-gb">
    <head>
        <title>WINDAUGA - Contact Us</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
        <!-- Meta is a Void tag -->
        <meta name="author" content="ACS Web Design">
        <meta name="description" content="Windauga Window Cleaners main website">
        <meta name="keywords" content="window cleaner, Trowbridge, waterfed pole, squeegy, cleaner, window, window cleaners Trowbridge, domestic, commercial, local, shiney, high standard, Gutter Clean">
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="https://fonts.googleapis.com/css?family=Muli" rel="stylesheet">
        <link rel="stylesheet" href="css/styles.css">
        <link rel="stylesheet" href="css/custom.css">
        <link rel="stylesheet" href="css/media.css">
        <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
        <script   src="https://code.jquery.com/jquery-3.3.1.js"   integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="   crossorigin="anonymous"></script>
        <script type="javascript" src="js/alterClass.js"></script>
        <script>
             $(document).ready(function(){
                // DOM is Ready
                $("#contact").submit(function(e)//
                {
                    //Form Submitted
                    var name = $("#name").val();//Methods are Getters and Setters.
                    var email = $("#email").val();
                    var tel = $("#tel").val();
                    var address = $("#address").val();
                    var message = $("#message").val();
                    var send = false; //Send FLAG

                    if(name != "")
                    {
                        //ALL OK
                        send = true;
                    }
                    else
                    {
                        //ERROR
                        send = false;
                        $("#name").css("border-color","#ff0000");
                    }

                    if(email != "" && send === true)
                    {
                        //ALL OK
                        send = true;
                    }
                    else
                    {
                        //ERROR
                        send = false;
                        if(email == "")
                        {
                            $("#email").css("border-color","#ff0000");
                        }

                    }

                    if(tel != "" && send === true)
                    {
                        //ALL OK
                        send = true;
                    }
                    else
                    {
                        //ERROR
                        send = false;
                        if(tel == "")
                        {
                            $("#tel").css("border-color","#ff0000");
                        }

                    }

                    if(address != "" && send === true)
                    {
                        //ALL OK
                        send = true;
                    }
                    else
                    {
                        //ERROR
                        send = false;
                        if(address == "")
                        {
                            $("#address").css("border-color","#ff0000");
                        }

                    }

                    if(message != "" && send === true)
                    {
                        //ALL OK
                        send = true;
                    }
                    else
                    {
                        //ERROR
                        send = false;
                        if(message == "")
                        {
                            $("#message").css("border-color","#ff0000");
                        }

                    }

                    if(send === true)
                    {
                        //Do nothing

                    }
                    else
                    {
                        //Stop form submitting
                        e.preventDefault();
                    }

                });// Submit Event

                $("#name, #email, #tel, #address, #message").focus(function()
                {
                    $(this).css("border-color","initial");

                }); //Focus Event


                $("#name, #email, #tel, #address, #message").blur(function()
                {
                    var tmp = $(this).val();

                    if(tmp != "")
                    {
                        $(this).next().css("visibility","visible");
                    }
                    else
                    {
                        $(this).css("border-color","#f00");
                    }

                });

                $("input[type='reset']").click(function() 
                {
                    $(".fa-check").css("visibility","hidden");
                    $("#name, #email, #tel, #address, #message").css("border-color","initial");
                });
            }); // DOC Ready
        </script>
    </head>
    <body>
        <?php
            include("includes/topnav.php");
        ?>
            <main>
        <?php
            include("includes/sidenav.php");
        ?>
            <p id="Content" class=" txt-c" style="color:#f00">CONTACT FORM UNAVAILABLE AT THE MOMENT, UNDER CONSTRUCTION, PLEASE FEEL FREE TO CALL OR EMAIL DIRECTLY VIA THE CONTACTS IN THE SIDE BAR 
            </p>
            <p id="Content" class=" txt-c">YOUR FREE QUOTE FOR WINDOW, CONSERVATORIES, OR GUTTERS AND FACIAS CLEANING 
            </p>
    <?php
        if($name != "" && $error === false)
        {
            /* Preparation for email sending*/
            $to = "juley@windauga.co.uk";
            $replyTo = "juley@windauga.co.uk";
            $em_subject = "Window Quote";

            /* Email Headers*/
            $headers = "From: $to\r\n";
            $headers .= "Reply-To: $to\r\n";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

            $em_message = "<html><body><h1>Email Subject:$em_subject</h1>";
            $em_message .= "<h2>Message</h2><p>$message</p>";
            $em_message .= "<h2>Name</h2><p>$name</p>";
            $em_message .= "<h2>Address</h2><p>$address</p>";
            $em_message .= "<h2>Phone Number</h2><p>$tel</p>";
            $em_message .= "<h2>Message</h2><p>$message</p>";
            $em_message .= "</body></html>";

            if(mail($to, $em_subject, $em_message, $headers)) {
                //Sent
                echo "<p class='success'>Thank you for the email!</p>";
            }
            else 
            {
                //Not sent
                echo "<p>Email Failed</p>";
                echo "<p>Subject = $em_subject</p>";
                echo "<p>Message = $em_message</p>";
                echo "<p>Headers = $headers</p>";
            }
        }
        else
        {

        if($errDescription != "")
        {
            echo "<p class='errorStyle'>Yikes Chief! You've trekked in the wrong neighbourhood! Error: $errDescription</p>";
        }


    ?> 
        <div class="container">  
                <form id="contact" method="post" action="contact.php">
                    <h3>Free Quote</h3>
                    <h4>Contact us today, and we will reply as soon as possible</h4>
                    <fieldset>
                        <input id="name" placeholder="Your name" type="text" tabindex="1" required autofocus>
                    </fieldset>
                    <fieldset>
                        <input id="email" placeholder="Your Email Address" type="email" tabindex="2" required>
                    </fieldset>
                    <fieldset>
                        <input id="tel" placeholder="Your Phone Number" type="tel" tabindex="3" required>
                    </fieldset>
                    <fieldset>
                        <input id="address" placeholder="Your Address" type="address" tabindex="4" required>
                    </fieldset>
                    <fieldset>
                        <textarea id="message" placeholder="Type of house, How many windows, service required, etc. Type your Message Here...." tabindex="5" required></textarea>
                    </fieldset>
                    <fieldset>
                        <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Submit</button>
                    </fieldset>
                    <fieldset>
                        <button name="reset" type="reset" id="contact-reset" value="Clear" data-submit="...Resetting">Reset</button>
                    </fieldset>
                </form>
            </div>
    <?php
        } //END if
    ?>
    </main>
    </body>
</html>

`

0 个答案:

没有答案