使用reCaptcha的表单 - PHP代码在本地发送邮件,但不在远程服务器上发送

时间:2017-07-03 18:57:26

标签: php ajax forms twitter-bootstrap

我已经从这里的教程(https://bootstrapious.com/p/bootstrap-recaptcha)创建了一个表单。我正在使用MAMP并在我的Mac上使用PHP设置了测试邮件服务器。

PHP代码在我的本地机器上完美地发送我的表单数据,但是当我将其上传到我的服务器(其他网站的表单使用PHP发送没有问题)时,表单数据不会发送。 (我已经用文字取代了reCaptcha秘密和网站密钥。)

HTML

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour
{

    void Start()
    {

    }

    private float length = 0;
    private bool SW = false;
    private Vector3 final;
    private Vector3 startpos;
    private Vector3 endpos;

    public GameObject basketball; //Basketball Obj
    public Rigidbody rbody;// Basketball Obj

    public float Force = 0.2f;

    void Update()
    {
        rbody = basketball.GetComponent<Rigidbody>();
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
        {
            final = Vector3.zero;
            length = 0;
            SW = false;
            Vector2 touchDeltaPosition = Input.GetTouch(0).position;
            startpos = new Vector3(touchDeltaPosition.x, 0, touchDeltaPosition.y);
        }
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
        {
            SW = true;
        }

        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Canceled)
        {
            SW = false;
        }

        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Stationary)
        {
            SW = false;
        }
        if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended)
        {
            if (SW)
            {
                Vector2 touchPosition = Input.GetTouch(0).position;
                endpos = new Vector3(touchPosition.x, 0, touchPosition.y);
                final = endpos - startpos;
                length = final.magnitude;
                rbody.AddForce(new Vector3(touchPosition.x, touchPosition.x + touchPosition.y, touchPosition.y) * Force);
            }
        }
    }
    void OnGUI()
    {
        GUI.Box(new Rect(50, 300, 500, 30), "length: " + length);
    }
}

AJAX

<form id="contact-form" action="process.php" method="post">
            <div class="form-heading">Please Contact Us</div>

            <div class="messages"></div>

            <div class="col-md-8">
                <div class="form-group">
                    <label for="form_name">Name *</label>
                    <input id="form_name" type="text" name="name" class="form-control" placeholder="Please enter your name *" required="required" data-error="Name is required.">
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <div class="col-md-8">
                <div class="form-group">
                    <label for="form_email">Email *</label>
                    <input id="form_email" type="email" name="email" class="form-control" placeholder="Please enter your email *" required="required" data-error="Valid email is required.">
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <div class="col-md-8">
                <div class="form-group">
                    <label for="form_phone">Phone</label>
                    <input id="form_phone" type="tel" name="phone" class="form-control" placeholder="Please enter your phone">
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <div class="col-md-12">
                <div class="form-group">
                    <label for="form_message">Message *</label>
                    <textarea id="form_message" name="message" class="form-control" placeholder="What's on your mind? *" rows="4" required="required" data-error="Please leave us a message."></textarea>
                    <div class="help-block with-errors"></div>
                </div>
            </div>

            <div class="g-recaptcha" data-sitekey="SITE KEY HERE"></div>

            <input id="submit-btn" type="submit" value="Submit" />
        </form>

PHP

$(function () {

// init the validator
// validator files are included in the download package
// otherwise download from http://1000hz.github.io/bootstrap-validator

$('#contact-form').validator();


// when the form is submitted
$('#contact-form').on('submit', function (e) {

    // if the validator does not prevent form submit
    if (!e.isDefaultPrevented()) {
        var url = "process.php";

        // POST values in the background the the script URL
        $.ajax({
            type: "POST",
            url: url,
            data: $(this).serialize(),
            success: function (data)
            {
                // data = JSON object that contact.php returns

                // we recieve the type of the message: success x danger and apply it to the 
                var messageAlert = 'alert-' + data.type;
                var messageText = data.message;

                // let's compose Bootstrap alert box HTML
                var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';

                // If we have messageAlert and messageText
                if (messageAlert && messageText) {
                    // inject the alert to .messages div in our form
                    $('#contact-form').find('.messages').html(alertBox);
                    // empty the form
                    $('#contact-form')[0].reset();
                    // reset the ReCaptcha
                    grecaptcha.reset();
                }
            }
        });
        return false;
    }
});
});

0 个答案:

没有答案