Bjaeg
Bjaeg

Reputation: 338

Google Apps Scripts - Email as string

If I get a variable and enter an email address, like so..

var emailAddress = '[email protected]';

Then this code (Below) will work and send an email to the above address.

var sendMail = MailApp.sendEmail({ to: emailAddress, subject: emailSubject, message: emailMessage});

If I dynamically enter an email address (through a google form) that is in column (10), the code above will fail. Am I not passing it as a string?

var emailAddress = e.values[10];

I have also tried the following to fix a sting issue:

var emailAddress = String(e.values[10]);

Upvotes: 0

Views: 128

Answers (1)

Ranjeeth Kumar Sara
Ranjeeth Kumar Sara

Reputation: 59

I already faced this issue, we can solve this issue by using serializedArray example: #emailForm is the id for the form we need to put email value to any variable I stored in newValues then get emailAddress as a string(var emailId = newValues.email.value;)

   var formValues = $("#emailForm").serializeArray();
    var newValues = {};
    formValues.forEach(function(x){
           newValues[x.name] = x;
    });
var emailId = newValues.email.value;

Upvotes: 1

Related Questions