Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send json message to api mandrill from html form

I have a html contact form and I need to send an email without php. I'm trying to used the mandrill API sending a JSON message. My function calling from the onsubmit is like this, but I'm not recieveing any message to my email.

function send() {
$.ajax({
    type: "POST",
    url: "https://mandrillapp.com/api/1.0/messages/send.json",
    data: {
    "key": "IL_tX9KjtDeZevJkN7YwHA",
    "message": {
        "text":document.getElementById("message").value,
        "subject": "Contacto desde la web",
        "from_email":document.getElementById("email").value,
        "from_name": document.getElementById("name").value,
        "to": [
            {
                "email": "[email protected]",
                "name": "Recipient Name",
                "type": "to"
            }
        ]
    },
    "async": false
    }
});
alert("Gracias por ponerte en contacto con nosotros.");

};
like image 656
user3662095 Avatar asked Aug 30 '26 19:08

user3662095


1 Answers

Why are you using Ajax with async: false ? You have got to test ajax addìng something like this to your call:

error: function(xhr, status, error) {

      var err = eval("(" + xhr.responseText + ")");
      alert(err.Message);
    }

You have also to move the success message alert this way:

success: function ( )
{
 alert ( " Done ! " );
};

In this way you can understand what is going wrong.

like image 167
kiks73 Avatar answered Sep 01 '26 08:09

kiks73



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!