我是编程新手,经过数十万小时的努力,我没有接近解决方案。任何帮助都会非常赞赏。 我有一个表单,我通过ajax发送到PHP(虽然我没有在域名后的地址栏中看到/process.php,或者这甚至重要?)。来自php 的确认会在页面上加载,但表单值的电子邮件不会发送。我非常努力地工作,而且真的相信我会得到这些东西,但是现在我需要一些帮助。可以在http://www.hydrodyneh2o.com查看实时版本。 提前谢谢。
$(document).ready(function(){
//Script for "Submit" button to submit and load 'submission confirmation'
$('#hydrodyne-form input[type="submit"]').click(function(e){
e.preventDefault();
//alert("never!");
$('#hydrodyne-form .warn').remove();
var fields = $('#hydrodyne-form').serializeArray();
$.ajax({
type : 'POST',
url : 'processForm.php',
data : fields,
dataType : 'json',
success: function(data) {
if (data.error) {
$.each(data.fields, function(k, v) {
$('.' + k).append('<span class="warn">' + v + '</span>');
$('.warn').fadeIn(700);
});
} else {
$('#form-content').fadeOut(700, function() {
$(this).hide();
$('#form-content').addClass('processing').html('Processing...').fadeIn(400);
$('#form-content').delay(1300).fadeOut(700).hide(function(){
$(this).removeClass('processing').html(data.confirm).fadeIn(400);
});
});
}
},
error: function(data) {
$('#form-content').hide().html('<p id="error" class="italic inside-text">*Error occurred</p>').fadeIn(700);
}
});
return false;
});
});
PHP(processForm.php):
<?php
$service = $_POST['service'];
$service_type = implode(",\r\n• ",$service);
if ($_POST) {
$expected_inputs = array('company', 'contact_name', 'phone_number', 'email');
$validation = array(
'company' => 'Company Name Required',
'contact_name' => 'Contact Name Required',
'phone_number' => 'Phone Number Required',
'email' => 'Email Address Required'
);
$company = stripslashes($_POST['company']);
$contact_name = stripslashes($_POST['contact_name']);
$phone_number = stripslashes($_POST['phone_number']);
$email = stripslashes($_POST['email']);
$project_summary = stripslashes($_POST['project_summary']);
$to = 'brian@bseifert.com';
$subject = 'You\'ve got a Website Inquiry!';
$message = "\r\n Contact Name: " . $contact_name .
$message = "\r\n\r\n Company: " . $company .
$message = "\r\n\r\n Phone Number: " . $phone_number .
$message = "\r\n\r\n Email Address: " . $email .
$message = "\r\n\r\n\r\n Type of Anticipated Service: \r\n\r\n " . $service_type .
$message = "\r\n\r\n\r\n Message: \r\n\r\n" . $project_summary;
$message = wordwrap($message, 80);
$errors = array();
$output = array();
foreach($expected_inputs as $key) {
if (array_key_exists($key, $_POST)) {
if (empty($_POST[$key])) {
$errors[$key] = $validation[$key];
} else {
$output[$key] = $_POST[$key];
}
} else {
$errors[$key] = $validation[$key];
}
}
if (!empty($errors)) {
$array = array('error' => true, 'fields' => $errors);
} else {
// PROCESS FORM
mail($to, $subject, $message) or die('not working!!!');
$confirm =
'<div id="logo" style="margin:80px 0 0 335px;"></div>
<img class="absolute" style="top:158px; left:265px;" src="IMG/inside-pgs/checkmark.png" alt="" />
<div class="inside-text thank-you">
<p>Your message has been sent.<br/> A representative from Hydrodyne will contact you<br/> as soon as possible.</p>
</div>';
$array = array('error' => false, 'confirm' => $confirm);
}
echo json_encode($array);
}
?>
HTML:
<div id="form-content">
<div id="inside-pg-heading">
<img src="IMG/inside-pgs/contact.gif" alt=""/>
</div><!-- end inside-pg-heading -->
<img class="hydroArrowContact absolute" src="IMG/inside-pgs/hydroArrowContact.png" alt="" />
<p class="hydroArrowContactText absolute">ydrodyne thanks you for stopping by, and asks that you use the form below <br>to ask any questions or place a request. We look forward to hearing from you!</p>
<div class="absolute" style="width:950px; top:132px; left:35px;">
<!-- <div id="response"></div> -->
<form id="hydrodyne-form" action="processForm.php" method="post">
<div id="formCol1">
<h5 class="form-heading inside-text bold italic"><span style="font-size:14px;">Fields marked with an asterisk (*) are required.</span></h5>
<div id="text-inputs" class="inside-text bold italic">
<div id="inputCol1">
<h4 class="company">* Company</h4>
<input type="text" name="company"<br/>
<h4 class="contact_name">* Contact Name</h4>
<input type="text" name="contact_name"<br/>
</div><!-- end inputCol1 -->
<div id="inputCol2">
<h4 class="phone_number">* Phone Number</h4>
<input type="text" name="phone_number"<br/>
<h4 class="email">* Email Address</h4>
<input type="text" name="email"<br/>
</div><!-- end inputCol2 -->
</div><!-- end text-inputs -->
<div class="clear"></div>
<h4 class="form-heading inside-text bold italic">Please check anticipated service(s)</h4>
<div class="checkboxes green">
<div id="checkboxCol1">
<input type="checkbox" name="service[]" value="Wastewater Flushing / Laundry"> Wastewater Flushing / Laundry<br/>
<input type="checkbox" name="service[]" value="Irrigation"> Irrigation<br/>
<input type="checkbox" name="service[]" value="Vehicle Washing"> Vehicle Washing<br/>
<input type="checkbox" name="service[]" value="Animal Feeding"> Animal Feeding
</div><!-- end checkboxCol1 -->
<div id="checkboxCol2">
<input type="checkbox" name="service[]" value="Commercial / Industrial Cooling"> Commercial / Industrial Cooling<br/>
<input type="checkbox" name="service[]" value="Commercial / Industrial Processing"> Commercial / Industrial Processing<br/>
<input type="checkbox" name="service[]" value="Fire Suppression"> Fire Suppression
</div><!-- end checkboxCol2 -->
</div><!-- end checkboxes -->
</div><!-- end formCol1 -->
<div id="formCol2">
<h5 class="form-heading inside-text bold italic">Provide Hydrodyne with more information by typing a brief message in the box below.</h5>
<textarea name="project_summary"></textarea>
<input type="submit" value="">
</div><!-- formCol2 -->
</form>
</div>
</div><!-- end form-content -->
答案 0 :(得分:0)
根据pHp文档:http://php.net/manual/en/function.mail.php#example-3381 您可以在mail();
中添加标题$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// PROCESS FORM
mail($to, $subject, $message, $headers) or die('not working!!!');
另外你应检查以下一行,因为我猜有一个无效的字符可能会产生任何不需要的pHp警告/错误;
$service_type = implode(",\r\n• ",$service);
它应该是:
$service_type = implode(",\r\n",$service);
答案 1 :(得分:0)
谢谢Nouphal.M!伙计,我花了很多时间寻找解决方案,而我需要做的就是检查我的垃圾邮件。我非常感谢大家的时间和精力!