Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅当我包含$headers时,PHP邮件表单才会发回错误_Php_Ajax_Forms_Email - Fatal编程技术网

仅当我包含$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

我有一个简单的表单设置。唯一的问题是我似乎不能在$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;
  });
});