doudansui6650 2012-08-27 04:11
浏览 53
已采纳

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;
    });
});
  • 写回答

1条回答 默认 最新

  • dttnb997315 2012-08-27 04:15
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退