POST方法不适用于联系论坛

时间:2019-05-06 17:47:46

标签: php html html5

我正在尝试使id =“ RecipientInput”在我的PHP代码上运行,但似乎不起作用。完成该操作后,我还想添加reCAPTCHA,但我认为这是个迷失的原因。如果我无法解决这个问题,就无法解决如何从Google实施反垃圾邮件api。

HTML

<form name="contactForm" id="contactForm" method="post" action="" novalidate="novalidate">
                    <fieldset>

                    <div class="form-field">
                        <input name="contactName" type="text" id="contactName" placeholder="Your Name" value="" minlength="2" required="" aria-required="true" class="full-width">
                    </div>
                    <div class="form-field">
                        <input name="contactEmail" type="email" id="contactEmail" placeholder="Your Email" value="" required="" aria-required="true" class="full-width">
                    </div>
                    <div class="form-field">
                        <input name="contactSubject" type="text" id="contactSubject" placeholder="Subject" value="" class="full-width">
                    </div>
                    <div class="form-field cl-custom-select">
                      <select class="full-width" id="RecipientInput">
                        <option value="Option 1">General Enquiry</option>
                        <option value="Option 2">Pivot</option>
                        <option value="Option 3">Napkin</option>
                      </select>
                    </div>
                    <div class="form-field">
                        <textarea name="contactMessage" id="contactMessage"placeholder="Your Message" rows="10" cols="50" required="" aria-required="true" class="full-width"></textarea>
                    </div>
                    <div class="form-field">
                        <button class="full-width btn-primary">Submit</button>
                        <div class="submit-loader">
                            <div class="text-loader">Sending...</div>
                            <div class="s-loader">
                                <div class="bounce1"></div>
                                <div class="bounce2"></div>
                                <div class="bounce3"></div>
                            </div>
                        </div>
                    </div>

                    </fieldset>
                </form>

PHP

<?php

// Replace this with your own email address
$siteOwnersEmail = 'my email address';


if($_POST) {

    $name = trim(stripslashes($_POST['contactName']));
    $email = trim(stripslashes($_POST['contactEmail']));
    $subject = trim(stripslashes($_POST['contactSubject']));
    // $selected_option = trim(stripslashes($_POST['RecipientInput']));
    $contact_message = trim(stripslashes($_POST['contactMessage']));

    // Check Name
    if (strlen($name) < 2) {
        $error['name'] = "Please enter your name.";
    }
    // Check Email
    if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
        $error['email'] = "Please enter a valid email address.";
    }
    // Check Message
    if (strlen($contact_message) < 15) {
        $error['message'] = "Please enter your message. It should have at least 15 characters.";
    }
    // Subject
    if ($subject == '') { $subject = "Contact Form Submission"; }


    // Set Message
    $message .= "<strong>Email from: </strong>" . $name . "<br />";
    $message .= "<strong>Email address: </strong>" . $email . "<br />";
    // $message .= "<strong>Selected Option: </strong>" . $selected_option . "<br />";
    $message .= "<strong>Message: </strong><br />";
    $message .= $contact_message;
    $message .= "<br /> ----- <br /> This email was sent from www.example.com </a>contact form. <br />";

    // Set From: header
    $from =  $name . " <" . $email . ">";

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


    if (!$error) {

        ini_set("sendmail_from", $siteOwnersEmail); // for windows server
        $mail = mail($siteOwnersEmail, $subject, $message, $headers);

        if ($mail) { echo "OK"; }
        else { echo "Something went wrong. Please try again."; }

    } # end if - no validation error

    else {

        $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
        $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
        $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;

        echo $response;

    } # end if - there was a validation error

}

?>

我正在尝试在我的测试服务器上进行连续测试,但此刻给我带来了问题。

1 个答案:

答案 0 :(得分:0)

您尚未为select定义X属性,name属性应该存在

替换

name

使用

<select class="full-width" id="RecipientInput">

屏幕截图 enter image description here