-2

I have a simple JavaScript/jQuery web app where users can enter an artist's name and receive a list of similar artists based off of the Spotify API. The Spotify API prints out a JSON array that I iterate over in order to show in the browser.

I would like to create an option where people can enter their email address and receive a copy of that output sent to them. Mandrill, as discussed here can only accept HTML content as opposed to dynamic JSON output. I was unaware that it required using PHP to parse the JSON into an HTML formatted snippet.

Edit: Upon further reflection and the answers, this is not the best way to go about it regardless. I have re-done this application anyway to use Node.js and npm options.

Yami Medina
  • 670
  • 10
  • 26

2 Answers2

1

use JSON.stringify to send as plaintext, and the receiver can use JSON.parse to parse it as JSON

1

Technically yes, there is a way.

You can not however include php or executable json inside an email. Well, you can, but it won't do anything. Why? Email clients by default do NOT run javascript code, and php is not going to be parse by an email client. Both for security reasons.

So, what can you do?

Using the json code, parse it with PHP on the server, and have it spit out an HTML formatted snippet that you can send to Mandrill. This is how you use Mandrill anyway.

See this question: PHP and Mandrill; on Stackoverflow

Community
  • 1
  • 1
David
  • 2,094
  • 3
  • 30
  • 47
  • thank you for your help, but I think i'm still unclear on this. The link gives me a php wrapper for the Mandrill API and how to use it, but it doesn't really explain the parsing. I don't have a JSON _file_, rather, I have the results of JSON queries populating my page. I'm looking for a link that explains parsing to PHP and sending a dynamic HTML snippet that changes depending on what the user enters. While PHP is implemented on my server, it hasn't been used in this particular code yet. I'm sorry if my question was not clear enough. – Yami Medina Sep 06 '15 at 23:59