I'm really new to Google Appscript, so please forgive me if this question sounds stupid.
I am trying to past variables from a PHP script into a Google App Script to utilise Gmail to send emails. I'm not quite sure if I am going about it the right way, but I'm trying to pass the variables to the appscript via a get request in the URL and access them that way.
//get the variables from the url and send email
function doGet(e){
var first_name = e.parameter.first_name;
var last_name = e.parameter.last_name;
var email = e.parameter.email;
var phone = e.parameter.phone;
GmailApp.sendEmail(first_name,last_name + email, phone);
}
doGet();
I tested it's ability to get the variables from the url via a get request by deploying it as a web app and passing some test variables in the URL:
https://script.google.com/macros/s/AKfycbzk14ZKDdsofFqx0vU2_kFIXLTduAMvy_G_9MyuS_d046MZIGQb/exec?first_name=testname&last_name=testname&phone=testname&email=testname
However, I get the following error on the page:
TypeError: Cannot read property "parameter" from undefined. (line 24, file "Code", project "email 6")
Could you please tell me what I am doing wrong here or is there an even better way to solve this sort of problem.
Thanks!
Remove the call to doGet() that you've placed after the function definition.
doGet() will be called automatically when the HTTP request is received, you don't need to call it explicitly.
When the HTTP request is received, any code not within a function is executed before doGet() is triggered. This means your current code is running doGet() with no parameters, thus hitting the "e" is undefined error, before the actual HTTP request is ever passed to doGet.
Otherwise the code in your function looks correct.