仅当我包含$headers时,PHP邮件表单才会发回错误
我有一个简单的表单设置。唯一的问题是我似乎不能在$header中包含“from:”和“reply to:”。每当我包含$headers时,它都会发回一个错误。没有它,表单就会发送 这是我的php,任何帮助都将不胜感激仅当我包含$headers时,PHP邮件表单才会发回错误,php,ajax,forms,email,Php,Ajax,Forms,Email,我有一个简单的表单设置。唯一的问题是我似乎不能在$header中包含“from:”和“reply to:”。每当我包含$headers时,它都会发回一个错误。没有它,表单就会发送 这是我的php,任何帮助都将不胜感激 <?php // Make accessible from AJAX only. if ( empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED
<?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;
});
});