Submit a JSON message to the Mandrill API using an HTML form

I am looking to incorporate a HTML contact form on my website and send an email without using PHP. I have attempted to use the Mandrill API to send a JSON message. However, despite setting up my function and calling it from the onsubmit, I am not receiving any emails in my inbox.

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": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3baa0b2b1b6bffda0b2bdb0bbb6a9fda0b2b6a993b4beb2babffdb0bcbe">[email protected]</a>",
                "name": "Recipient Name",
                "type": "to"
            }
        ]
    },
    "async": false
    }
});
alert("Thank you for contacting us.");

};

Answer №1

What's the reason for using Ajax with async: false? Have you considered testing your Ajax calls by adding error handling like this:

error: function(xhr, status, error) {

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

Additionally, remember to display the success message alert in this manner:

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

By following these steps, you'll be able to troubleshoot any issues more effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Posting Json data to Influxdb using REST API

How can I upload a JSON using Rest Api on Influx? I noticed that when reading data from Influx using Rest+query, it comes in JSON format. However, now they are saying that JSON is deprecated for uploading and we must use binary format instead. Is this rea ...

What are the steps to troubleshooting using VS Code and Chrome browser with Webpack?

Can anyone provide guidance on how to debug webpack in VS Code with the Chrome browser? As a beginner in programming, I'm struggling because webpack minifies everything into one line which makes traditional debugging methods ineffective. I haven' ...

Understanding the process of verifying signatures with Cloud KMS

I've been struggling to confirm the validity of a signature generated using Google's cloud KMS, as I'm consistently receiving invalid responses. Here's my approach to testing it: const versionName = client.cryptoKeyVersionPath( p ...

Implementing a method to track and monitor significant alterations in component properties

When initializing my component, I use the following code snippet: <custom :opts="{map: false}"></custom> In the HTML, there is a similar structure like this: <template id="custom"> <div v-if="opts.map"> I'm awesome ...

Deserialize the JSON file stored on the disk and convert it directly into an object

Currently, I am attempting to deserialize a JSON file stored on the local disk into an object. The code snippet provided below works fine when downloading the file from the web: var client = new HttpClient(); using (var s = await client.GetStreamAsync(fil ...

My large decimal number is unable to be saved by MySQL

My number is 34.59704151614417 When I save it with datatype decimal(16,14), MySQL changes it to 34.59704151614400 because it only saves up to 12 digits after the decimal point. This is my array: Array ( [geometry] => Array ...

Exploring how Java can parse and read JSON using the Jackson library, specifically

I am working with a JSON file that contains an array and I have successfully extracted the data. However, I am struggling to figure out how to print out all the values within the array. Although I can manually select a specific element (like the 3rd car in ...

Download an image file using JavaScript and HTML from a specified image URL

As someone who is new to JS and HTML, I am currently working on a project involving the creation of pie charts using Google Charts through an HTML API. I've successfully generated the chart and obtained the image URL. However, when I use window.open( ...

The slider thumb is not showing up properly on Microsoft Edge

Hey there! I'm experiencing an issue with the range slider's thumb display in Microsoft Edge. It appears to be positioned inside the track rather than outside as intended. Take a look at this snapshot for clarification: https://i.stack.imgur.co ...

leveraging array elements in the data and label properties of a chart.js chart

I would like to assign the values of an array to the data and label fields within a chart.js dataset. Below is the code executed upon successfully fetching JSON data using an AJAX call. The fetched JSON data is then stored in an array. Data = jQuery.pars ...

Guide to creating a cryptosystem using a Synchronous Stream Cipher with Vue js

I am currently working with a pseudo-random number generator that creates binary numbers using a user-supplied polynomial and the LFSR method. To enhance the process, I need to convert a loaded file into binary format so that I can apply the XOR operatio ...

The oninput event in IE10 is consistently triggered upon redirection

I have encountered a strange issue with IE10 when redirecting the page on an 'oninput' event, which does not occur with Chrome. I have simplified the code to demonstrate the problem: <html> <head> <script type="text/javascript&g ...

Display HTML content within a Material-UI Card component using React

Currently, I am utilizing the < CardHeader /> component nested within a < Card />. <CardHeader title={card.title} subheader={`${moment(card.createdAt).startOf('minute').fromNow()}` + ' by ' + <div>ABC</div>}/ ...

Tips for utilizing ng-repeat with standard JSON data structures

I have a JSON structure like this: [{ Entry: [{ ID:123, Name: 'XYZ', Address: '600, PA' }, { ID:123, Name: 'ABC', Address: '700, PA' }, { ID:321, Name: 'RRR', ...

Is there a way to modify the value of a constructor key once it has already been defined?

I am currently working on a simple constructor exercise where I need to update a value after the constructor has been created. Even after changing the value to true, the cat is still not making its noise. Challenge parameters The constructor function wi ...

Tips on arranging a parent-child JSON array structure for easier parsing of JSON data

Having trouble parsing the following JSON output using jQuery. The issue arises when trying to parse the "pprice" value, resulting in an "undefined" error. { "response": [ {"instances": [ { "instanceID": "000001", "instanceOS": "FreeBSD", "instanceVersion ...

Implement custom material-ui styles exclusively for mobile displays

When working with Material-UI in react, I am wondering if there is a way to apply theme provider overrides only in mobile view. Specifically, I am using the <Card> component and would like to remove the boxShadow of the card when it's displayed ...

What is the best way to populate nested elements with jQuery?

I am trying to showcase the latest NEWS headlines on my website by populating them using Jquery. Despite writing the necessary code, I am facing an issue where nothing appears on the webpage. Below is the HTML code snippet: <div class="col-md-4"> ...

Guide to adding a line break following each set of 200 characters utilizing jQuery

I have a text input field where I need to enter some data. My requirement is to automatically add a line break after every 200 characters using JavaScript or jQuery. For example: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ...

Error: The JSON response cannot be parsed due to an invalid label syntax

After making a request from my WS using jQuery, I received the following response: { "SkyWinResponse": { "statuscode": 0, "message": "ok\n ", "rowsaffected": 1, "results": { "result": { ...