1

好的,所以我有一个使用 PHP 向电子邮件地址发送邮件的表单。我还有一个 jQuery/AJAX 部分,它可以在不重新加载页面的情况下验证表单并执行 PHP。由于某种原因,来自兴趣下拉列表的产品兴趣值未通过电子邮件传递。我错过了什么?我一直在把自己逼疯。谢谢!

这是表格:

        <div class="contact-form">
            <div class="row">
                    <div class="field"><input type="text" id="first" name="first" class="input" placeholder="First Name"></div>
                    <div class="field"><input type="text" id="last" name="last" class="input" placeholder="Last Name"></div>
                    <div class="field"><input type="text" id="telephone" name="telephone" class="input" placeholder="Phone Number"></div>
            </div>
            <div class="row">
                    <div class="field"><input type="email" id="email" name="email" class="input" placeholder="E-mail"></div>
                    <div class="field">
                                        <select class="select" name="interest" id="interest">
                                            <optgroup label="Countwise Products:">
                                                  <option value="I-Count">I-Count</option>
                                                  <option value="Q-Count">Q-Count</option>
                                                  <option value="D-Count">D-Count</option>
                                                  <option value="Z-Count">Z-Count</option>
                                             </optgroup>
                                        </select> 
                    </div>
                    <input type="submit" value="Get Better Results!" class="button3 dark-blue submit"/>
                    <span class="error" style="display:none">All Fields Are Required!</span>
                    <span class="success" style="display:none">Contact Form Submitted Successfully</span>   
            </div>
        </div>


    </form>

这是标题为 header_form_email.php 的 PHP

<?php

// POST Variables
//Name
$first = $_POST['first'];
$last = $_POST['last'];
//Phone
$telephone = $_POST['telephone'];
//E-mail 
$email = $_POST['email'];
//Interest
$interest= $_POST['interest'];

// Contact subject
$subject = "CountWise Website - Sales Request";

$name =  "$first" . " " . "$last";



$message = "You have received a new information request from Countwise.com\n".
"Name: " . "$name\n".
"Phone: " . "$telephone\n".
"Email: " . "$email\n".
"Product Interest: " . "$interest";

// From
$mailheader = "From: $email \r\n";

// Enter your email address
$to ="kelly@drastikdesigns.com";

$send_contact=mail($to,$subject,$message,$mailheader);

// Check, if message sent to your email
if($send_contact){
echo "<strong>We have received your information and will be in contact you shortly. Thank you.</strong>" ;
}
else {
echo "ERROR";
}
?>

这是 AJAX

$(function() {
    $(".submit").click(function() {
        var first = $("#first").val();
        var last = $("#last").val();
        var telephone = $("#telephone").val();
        var email = $("#email").val();
        var interest = $("#interest").val();
        var dataString = 'first=' + first + '&last=' + last + '&telephone=' + telephone + '&email=' + email + '&interest' + interest;

        if (first == '' || last == '' || telephone == '' || email == '') {
            $('.success').fadeOut(200).hide();
            $('.error').fadeOut(200).show();
        }
        else {
            $.ajax({
                type: "POST",
                url: "http://www.drastikdesigns.com/clients/countwise/php/header_form_email.php",
                data: dataString,
                success: function() {
                    $('.success').fadeIn(200).show();
                    $('.error').fadeOut(200).hide();
                }
            });
        }
        return false;
    });
});
4

1 回答 1

4

你忘了等号:

'&interest=' + interest;

顺便说一句,为什么不这样做:

data:$("#formid").serialize(),

这将为您节省大量时间和头痛。第二点,在查看通过 ajax 发送的标头时,使用 firebug/developers tools/chrome 肯定会有所帮助。

于 2012-08-27T04:15:05.517 回答