我有一个简单的表单设置。唯一的问题是我似乎不能在我的$ header中包含'from:'和'reply-to:'。每当我包含$ headers时,它都会发回错误。如果没有它,表格就会发送。
这是我的php,非常感谢任何帮助。
<?php
// Make accessible from AJAX only.
if ( empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) != 'xmlhttprequest' )
header( 'Location: /' );
$name = htmlspecialchars($_POST['name']);
$website = htmlspecialchars($_POST['website']);
$email = htmlspecialchars($_POST['email']);
$phone = htmlspecialchars($_POST['phone']);
$products = htmlspecialchars($_POST['products']);
$message = $_POST['message'];
if ( $name ) {
$e_message = 'Name: ' . $name . "\r\n\r\n";
$e_message .= 'Company Website: ' . $website . "\r\n\r\n";
$e_message .= 'Email: ' . $email . "\r\n\r\n";
$e_message .= 'Phone: ' . $phone . "\r\n\r\n";
$e_message .= 'Products currently being sold: ' . $products . "\r\n\r\n";
$e_message .= 'Message: ' . "\r\n" . $message;
$to = 'kmist41@gmail.com, support@taurusprocessing.com';
$subject = 'Contact Request';
$headers = 'From: Someone <someone@somewhere.com>' . "\r\n" .
'Reply-To: ' . $email . "\r\n" ;
if ( mail( $to, $subject, $e_message, $headers ) ) {
die('success');
} else {
die('error');
}
} else {
die('invalid');
}
?>
jQuery的:
$(function() {
// Contact form
$('#form').on('submit', function() {
var name = $('#field-name').val(),
website = $('#field-website').val(),
email = $('#field-email').val(),
phone = $('#field-phone').val(),
products = $('#field-products').val(),
message = $('#field-message').val(),
valid = true,
$form = $(this);
if (
name === '' ||
email === '' ||
message === ''
) {
valid = false;
}
if (valid) {
$.post('send-form.php',
$(this).serialize(),
function(resp) {
if (resp == 'success') {
$('.submission-error', $form).hide();
$('.error', $form).hide();
$form[0].reset();
$('.success', $form).show();
} else {
$('.submission-error', $form).show();
}
}
);
} else {
$('.error', this).show();
}
return false;
});
});