dspld86684 2018-10-12 11:28
浏览 389

PHP在提交联系表单错误后发送电子邮件POST http://www.if.com/mail/mail.php 404(未找到) - jquery-3.1.1.min.js:4

I'm trying to send e-mail with data from contact form on submit using PHP but i get this error > POST http://www.if.com/mail/mail.php 404 (Not Found) ... jquery-3.1.1.min.js:4

In my contact.html i have the code for my contact form.

<div class="container">
        <div class="row justify-content-between">
         
          <div class="col-md-6 col-12">
            <div class="boxed boxed--border">
              <form class="form-email row mx-0" action="contact.php" method="POST" data-success="Thanks for your enquiry, we'll be in touch shortly." data-error="Please fill in all fields correctly.">
                <div class="col-md-6 col-12">
                  <label>Your name</label>
                  <input type="text" name="name" class="validate-required">
                </div>
                <div class="col-md-6 col-12">
                  <label>Email address</label>
                  <input type="email" name="email" class="validate-required validate-email">
                </div>
                <div class="col-md-6 col-12">
                  <label>Company</label>
                  <input type="text" name="company" class="validate-required">
                </div>
                <div class="col-md-6 col-12">
                  <label>Phone number</label>
                  <input type="text" name="phone" class="validate-required">
                </div>
                <div class="col-md-6 col-12">
                  <div class="input-select">
                    <select name="function">
                      <option selected="" value="Default">Function</option>
                      <option value="">CEO</option>
                      <option value="">Director</option>
                      <option value="">Commercial</option>
                      <option value="">Engineer</option>
                      <option value="">Project manager</option>
                      <option value="">HR Manager</option>
                      <option value="">Other</option>
                  </select>
                  </div>
                </div>
                <div class="col-md-6 col-12">
                  <div class="input-select">
                    <select name="country">
                      <option selected="" value="Default">Country</option>
                      <option value="">Austria</option>
                      <option value="">Slovenia</option>
                      <option value="">Romania</option>
                  </select>
                  </div>
                </div>
                <div class="col-md-12">
                  <div class="input-checkbox">
                    <input id="check-test" type="checkbox" name="agree" />
                    <label for="check-test"></label>
                  </div>
                  <span>I have read and agree to the <a href="#">terms and conditions</a></span>
                </div>
                
                <div class="col-md-5 col-lg-4 col-6"> <button type="submit" name="submit" class="btn btn--primary type--uppercase">Send Enquiry</button> </div>
              </form>
            </div>
          </div>
        </div>
      </div>

In my contact.php I have this code

    <?php
// let's do the sending

if (isset($_POST['submit'])) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $to = 'example@gmail.com';
    $subject = "Contact form";
    $body = '<html>
                <body>
                    <h2>Contact</h2>
                    <hr>
                    <p>Name: ' .$name. '</p>
                    <p>Email: ' .$email. '</p>
                    <p>Phone: ' .$phone. '</p>
                    <p>Company: ' .$company. '</p>
                    <p>Function: ' .$function. '</p>
                    <p>Country: ' .$country. '</p>
                </body> 
             </html>';
    //headers
    $headers = "From: ".$name." <".$email.">
";
    $headers = "Reply-To: ".$email."
";
    $headers = "MIME-VERSION: 1.8
";
    $headers = "Content-type: text/html; charset-utf-8";

    //send
    $send = mail($to, $subject, $body, $headers);
    if($send) {
        echo '<br>';
        echo 'Thanks for contacting us. We will be with you shortly.';
    }
    else{
        echo 'error';
    }}

When i add all code in one .php file i have the same error. I don't know where is the error. Please help me... Also i try with java script and there is the same error.

$(function () {

    $('#contact-form').on('submit', function (e) {
        if (!e.isDefaultPrevented()) {
            var url = "contact.php";

            $.ajax({
                type: "POST",
                url: url,
                data: $(this).serialize(),
                success: function (data) {
                    var messageAlert = 'alert-' + data.type;
                    var messageText = data.message;

                    var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';
                    if (messageAlert && messageText) {
                        $('#contact-form').find('.messages').html(alertBox);
                        $('#contact-form')[0].reset();
                    }
                }
            });
            return false;
        }
    })
});

</div>
  • 写回答

2条回答 默认 最新

  • dty98339 2018-10-12 11:59
    关注

    Add form id like this....I think you missed that.

    <form class="form-email row mx-0" action="contact.php" id="contact-form" method="POST" data-success="Thanks for your enquiry, we'll be in touch shortly." data-error="Please fill in all fields correctly.">
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法