I have an HTML form with a textarea which contains a default message which can be edited by the user. The HTML is as follows:
To: Email address >
</div>
<div class="form-group" id="ccInput">
<label for="ccAddress"><i class="fa fa-envelope" aria-hidden="true"></i> Cc: Email address</label>
<input type="text" data-role="tagsinput" multiple="multiple" name="ccAddress" class="form-control" id="ccAddress" aria-describedby="emailHelp" value=<?=ccEmail?>>
</div>
<div class="form-group">
<label for="subject"><i class="fa fa-info-circle" aria-hidden="true"></i> Subject</label>
<input type="input" name="subject" class="form-control" id="subject" value=<?=mailSubject?>>
</div>
<div class="form-group">
<label for="subject"><i class="fa fa-pencil" aria-hidden="true"></i> Message</label>
<div id="blankInput"></div>
<textarea class="form-control" rows="12" id="text" name="message">Dear <?= firstName ?> <?= surName ?>,
<?= mailBody ?>
Kind regards,
<?= contractorName ?>
<?= contractorTitle ?></textarea>
</div>
<div class="form-group" id="pdfForm">
<label for="pdfUrl"><i class="fa fa-paperclip" aria-hidden="true"></i> PDF Attachment</label>
<input type="url" name="pdfUrl" class="form-control" id="pdfUrl" value=<?=pdfUrl?>>
</div>
</div>
<button type="submit" class="btn btn-primary googleGreen" id="load" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Sending">Send Email</button>
<button type="button" class="btn btn-primary googleGray" onClick="google.script.host.close()">Cancel</button>
<input type="hidden" name="process" value=<?= process ?>>
<input type="hidden" name="fromEmail" value=<?= fromEmail ?>>
</form>
</div>
</div>
I then have the following script to send the email in my .gs file:
var toEmail = form.toAddress;
var ccEmail = form.ccAddress;
var fromEmail = form.fromEmail;
var subject = form.subject;
var message = form.message;
var sender = form.contractorName;
GmailApp.sendEmail(
toEmail,
subject,
message,
{
attachments:[pdfFile],
cc: ccEmail,
from: fromEmail,
name: sender
});
}
This all works fine, but the problem with the textarea is that obviously it cannot process HTML. I want to add an email signature containing several styles and a logo etc. but as far as I can see the only way to do this is the use the htmlBody advanced option. But then I can't use the textarea!
Is there a way to combine these 2 elements so that I can add some HTML at the end of the body which would contain the signature?
\n
and replace them with html break tags<br>
If you don't do that, and you put the plain text into the HTML the new lines and spacing will be removed. You could do a global replace on all\n
newline character codes, and replace with<br>
tags. – Alan Wells