PHP联系人表单不发送电子邮件

时间:2018-07-01 10:48:45

标签: php contact-form

我已经创建了此联系表单,并且不断返回无法发送电子邮件的消息。布尔值不断返回false。

Contactform.php(表单站点):

<div class="container">


    <center class="contacttext"><h3>Contact opnemen</h3></center>



  <form class"contact-form" action="contact.php" method="POST">
    <input type="text" required name="naam" placeholder="naam">
    <input type="text" required name="mail" placeholder="E-mailadres">
    <input type="text" required name="onderwerp" placeholder="Onderwerp">
    <textarea name="bericht"  required placeholder="bericht"></textarea>
    <input type="submit" value="verstuur"></input>

<?php
    if (isset($_GET["submit"])) {
        $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        if ($_GET["submit"] == "empty") {
            echo "<center><p class='error'> Je hebt niet alle velden ingevuld!</p></center>";
            exit();
        }
        elseif ($_GET["submit"] == "char") {
            echo "<center><p class='error'> Je hebt ongeldige karakters gebruikt!</p></center>";
            exit();
        }
        elseif ($_GET["submit"] == "invalidemail") {
            echo "<center><p class='error'> Je hebt een ongeldig e-mailadres gebruikt!</p></center>";
            exit();
        }
        elseif ($_GET["submit"] == "failed") {
            echo "<center><p class='error'> Het bericht kon niet verstuurd worden, probeer dit later opnieuw!</p></center>";
            exit();   
        }
        elseif ($_GET["submit"] == "succes") {
            echo "<center><p class='succes'> Het bericht is succesvol verstuurd!</p></center>";
            exit();   
        }
    }

?>


</form>
</div>

Contact.php(发送脚本):

<?php   

if (isset($_POST['naam'])) {
    $naam = $_POST['naam'];
    $onderwerp = $_POST['onderwerp'];
    $mailVan = $_POST['mail'];
    $bericht = $_POST['bericht'];

    $mailNaar = "name@domain.com";
    $headers = "From: ".$mailVan;
    $txt = "Je hebt een e-mail gekregen van ".$naam.".\n\n".$bericht;
    $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";


    if (!filter_var($mailVan, FILTER_VALIDATE_EMAIL)) {
        header("Location: contactform.php?submit=invalidemail");
        exit();
    } 
    elseif (preg_match("[a-zA-Z]", $naam)) {
        header("Location: contactform.php?submit=char");
        exit();
    } 
    else {
        $succes = mail($mailNaar, $onderwerp, $txt, $headers);
        if ($succes) {
            header("Location: contactform.php?submit=succes");
        } else {
            header("Location: contactform.php?submit=failed");
        }

        exit();
   }



}

?>

该电子邮件当然是有效的电子邮件,但我现在对其进行了更改。

如果需要CSS类:

    .error {
color: red;

    }


.container {
    border-radius: 5px;
    background-color: #F5A105;
    height: 700spx;
    width: 700px;
    padding: 20px;
    margin: auto;
}

有人知道为什么它不发送电子邮件吗?该网站正在USBWeb服务器上运行以进行测试。

0 个答案:

没有答案