Trying to send data from Google App Script to a php site which sends an email from my database. For most of the date it is no problem I send it via the url(example.com/example.php?id=test&id2=test2&id3=test3).
For most of the data it is no problem except for the third parameter, the given value is way longer than the other two and may contain newlines as well. My idea was to send the third(or all values) as JSON object. My Google AppScript code so far:
function sendData(){
var options = {'text' : 'A longer example text'} ;
try {
var url = "https://example.com/example.php?id1=test1&id2=test2&id3="+options;
var httpRequest = UrlFetchApp.fetch(url, options).getContentText();
}
catch(e){
Logger.log(e);
}
return;
}
My PHP code:
<?php
require 'includes/functions.php';
include_once 'config.php';
include 'ChromePhp.php';
$email = $_GET["id1"];
$name = $_GET["id2"];
$text = $_GET["id3"];
$json = json_decode($text, true);
ChromePhp::log($json->text);
if(strpos($text, "\n") !== FALSE) {
$text = str_replace("\n", "<br>", $text);
}
$replace_to_standard=[$name, $text];
$replace_standard =['nametochange', 'textochange'];
$delivery_added = str_replace($replace_standard, $replace_to_standard, file_get_contents('standardMail.html'));
echo "" . $delivery_added . "";
$m = new MailSender;
$m-> sendMail($email, $email, $delivery_added, "Mail All");
The chrome logger will log "null"
Any ideas?