在localhost上找不到联系表单

时间:2017-05-04 13:51:53

标签: php node.js localhost contact-form

当我从联系表单发送消息时出现以下错误:

form

我不确定它是否与我的文件结构有关或尝试在localhost上发布POST。

我检查过的事情:

  1. method="post"ajax
  2. type: POST请求为inputs
  3. name='something'localhost:3000
  4. 页面在const express = require('express'), app = express(), logger = require('morgan'), bodyParser = require('body-parser') // environment port const port = process.env.PORT || 3000 app.use(express.static(process.env.PWD + '/client')) app.use(logger('dev')) app.use(bodyParser.urlencoded({extended: true})) app.use(bodyParser.json()) app.get('/', (req, res) => { res.render('index') }) app.listen(port, (err) => { console.log(err || 'listening on port ' + port) })
  5. 上正常运行

    我需要修理什么?

    这是我的应用程序的结构:

    app.js:

    client/js/contact_me.js

    以下是 $.ajax({ url: "../../mail/contact_me.php", type: "POST", data: { name: name, phone: phone, email: email, message: message }, cache: false, success: function() { // Enable button & show success message $("#btnSubmit").attr("disabled", false); $('#success').html("<div class='alert alert-success'>"); $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;") .append("</button>"); $('#success > .alert-success') .append("<strong>Your message has been sent. </strong>"); $('#success > .alert-success') .append('</div>'); //clear all fields $('#contactForm').trigger("reset"); }, error: function() { // Fail message $('#success').html("<div class='alert alert-danger'>"); $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;") .append("</button>"); $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!"); $('#success > .alert-danger').append('</div>'); //clear all fields // $('#contactForm').trigger("reset"); }, }); 中的ajax请求:

    <?php
    // Check for empty fields
    if(empty($_POST['name'])        ||
       empty($_POST['email'])       ||
       empty($_POST['phone'])       ||
       empty($_POST['message']) ||
       !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
       {
        echo "No arguments Provided!";
        return false;
       }
    
    $name = strip_tags(htmlspecialchars($_POST['name']));
    $email_address = strip_tags(htmlspecialchars($_POST['email']));
    $phone = strip_tags(htmlspecialchars($_POST['phone']));
    $message = strip_tags(htmlspecialchars($_POST['message']));
    
    // Create the email and send the message
    $to = 'myemail@gmail.com'; 
    $email_subject = "Website Contact Form:  $name";
    $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
    $headers = "From: noreply@yourdomain.com\n";
    $headers .= "Reply-To: $email_address";
    mail($to,$email_subject,$email_body,$headers);
    return true;
    ?>
    

    邮件/ contact_me.php:

    client/index.html

    以下是<form name="sentMessage" method="post" id="contactForm" novalidate> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label for="name">Name</label> <input name="name" type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label for="email">Email Address</label> <input name="email" type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label for="phone">Phone Number</label> <input name="phone" type="tel" class="form-control" placeholder="Phone Number" id="phone" required data-validation-required-message="Please enter your phone number."> <p class="help-block text-danger"></p> </div> </div> <div class="row control-group"> <div class="form-group col-xs-12 floating-label-form-group controls"> <label for="message">Message</label> <textarea name="message" rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea> <p class="help-block text-danger"></p> </div> </div> <br> <div id="success"></div> <div class="row"> <div class="form-group col-xs-12"> <button type="submit" class="btn btn-success btn-lg">Send</button> </div> </div> </form> 中的表单:

    >"test.csv" (
      for %%i in ... (
        ...
        ...
      )
    )
    

0 个答案:

没有答案