簡體   English   中英

表格未發送

[英]Form isn't sending

我正在為客戶准備一個站點,並且試圖從頭開始創建表單,而不是使用插件。

我不確定我要去哪里。 該頁面會一直刷新到主頁,並且不會發送電子郵件。

有人可以在我的代碼中指出我哪里出錯了...

提前致謝!

<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $message = $_POST['message'];
        $from = 'From: Test'; 
        $to = 'email@example.com'; 
        $subject = 'Hello';

        if ($name == "" OR $email == "") {
            echo "You must specify a value for name, email address, and message.";
            exit;
        }

        foreach( $_POST as $value ){
                if( stripos($value,'Content-Type:') !== FALSE ){
                    echo "There was a problem with the information you entered.";
                    exit;
                }
        }

        require_once("assets/inc/phpmailer/class.phpmailer.php");
        $mail = new PHPMailer();

        if (!$mail->ValidateAddress($email)){
            echo "You must specify a valid email address.";
        }

        $body = "From: $name\n E-Mail: $email\n Message:\n $message";

        header("Location: http://natashamcdiarmid.com/clients/JLP/wp/contact/?status=thanks");
        exit;
    }
?>




<?php if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
    <p>Thanks, I'll get back to your shortly!</p>
<?php } else ?>

<form method="post" action="contact">

    <p><label>Name</label></p>
    <input name="name" placeholder="Type Here">

    <p><label>Email</label></p>
    <input name="email" type="email" placeholder="Type Here">

    <p><label>Message</label></p>
    <textarea name="message" placeholder="Type Here"></textarea>

    <p><label>*What is 2+2?</label></p>
    <input name="human" placeholder="Type Here">

    <p><input id="submit" name="submit" type="submit" value="Submit"></p>

    <?php
        if ($_POST['submit']) {
            if (mail ($to, $subject, $body, $from)) { 
                echo '<p>Your message has been sent!</p>';
            } else { 
                echo '<p>Something went wrong, go back and try again!</p>'; 
            }
        }
    ?>

</form>    

您要發布到的表單目錄不多。

<form method="post" action="contact">  
 should it be contact.php?

該操作應該是表單處理程序的目錄

WordPress的一個主要問題總是讓我困擾,那就是它使用了一些具有通用名稱的請求變量,而將其弄亂會導致無法預料的錯誤。 例如, name參數用於查找和顯示當前帖子或網頁。

嘗試將您的name字段重命名為其他name ,例如your_name

當我創建要在WordPress中使用的表單時,通常會在每個字段前添加自定義acme_contact_name ,例如acme_contact_nameacme_contact_email等。鍵入更多一些,但更安全。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM