I have a little php script on the server which takes a JSON dump of data from a curl command on a remote server.
The php script e-mails me via postmark the result however it just e-mails the raw JSON data at the moment which can be obviously quite unreadable.
I'd like to beautify and then parse the data if possible before sending it.
So the current php script is
<?php
$payload = file_get_contents('php://input');
$serverToken = "*****";
$json = json_encode(array(
'From' => 'email',
'To' => 'email',
'Subject' => 'Server Info',
'HtmlBody' => $payload,
'TextBody' => $payload
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.postmarkapp.com/email');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'X-Postmark-Server-Token: ' . $serverToken
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$response = json_decode(curl_exec($ch), true);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
and I'd get e-mailed this...
{ "IP": "78.122.144", "SERIAL" : "C02SQ5888TUA", "Date", "Fri 23 Jun 2017 18:05:01 BST" }
A beautifier online would turn it into
{
"IP": "78.122.144",
"SERIAL": "C02SQ5888TUA",
"DATE": "Fri 23 Jun 2017 18:05:01 BST"
}
But i'd really like the content of the email to look like this...
IP: 78.122.144
SERIAL: C02SQ5888TUA
DATE: Fri 23 Jun 2017 18:05:01 BST
With the {} " and , removed.
Could anyone suggest how to have the script/server do that, and the icing on the cake would be to put the serial number above into the subject of the email too.
An example curl command is:
curl -H "Content-Type: application/json" https://url.com/first.php -d '{ "IP Address": "'"$(dig +short myip.opendns.com @resolver1.opendns.com)"'", "SERIAL": "'"$(system_profiler SPHardwareDataType | awk '/Serial/ {print $4}')"'", "Date", "'"$(date)"'" }'