gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:22:38 27 4
gpt4 key购买 nike

好的,我有一个使用 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;
});
});

最佳答案

你忘记了等号:

'&interest=' + interest;

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

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

这将为您节省大量时间并减少头痛。第二点,在查看通过 ajax 发送的 header 时,使用 firebug/开发人员工具/chrome 绝对有帮助。

关于PHP/AJAX 邮件联系表单 - 电子邮件消息的一部分未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12136136/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com