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.">
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器