PHP / AJAX邮件联系表单 - 未显示的电子邮件的一部分

PHP / AJAX邮件联系表单 - 未显示的电子邮件的一部分

问题描述:

Okay so I have a form that is using PHP to mail to an e-mail address. I also have a jQuery/AJAX section that validates the form without reloading the page and executes the PHP. For some reason the Product Interest value from the interest drop down is not coming through in the e-mail. What am I missing? I've been driving myself mad with this. Thanks!

This is the form:

        <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>

This is the PHP for titled header_form_email.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
".
"Name: " . "$name
".
"Phone: " . "$telephone
".
"Email: " . "$email
".
"Product Interest: " . "$interest";

// From
$mailheader = "From: $email 
";

// 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";
}
?>

This is the 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;
    });
});

You forgot the equals:

'&interest=' + interest;

On a side note, why not just do:

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

That will save you tons of time and headache. Second point, using firebug/developers tools/chrome definitely helps when it comes to viewing the headers sent via ajax.