jordan rhea header

Contact Form

September 15th, 2017

Create a contact form on your website hosted on a static site.

When you have a cheap shared server package from one of the giant hosting services, it can be hard to build a website that don’t involve giant Wordpress add-ons.

There are more efficient ways to do these things! One of those ways is a contact form to get feedback from your users, just like the contact form on my page!

See the Pen Contact Form by jordan rhea (@rheajt) on CodePen.

You just need to create a script on your drive and deploy it as a web app. You want to make sure that you Execute the app as yourself and make it accessible by Anyone, even anonymous. Then just use the code below. Be sure to put in your own data!

function doPost(e) {
  var json = JSON.parse(e.postData.contents);

  var response = sendMail({
    subject: json.subject,
    body: json.body,

  return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(

function sendMail(data) {
  try {
    var html = HtmlService.createTemplateFromFile('email'); =; =;
    html.subject = data.subject;
    html.body = data.body;

    //This should probably be changed to the MailApp service now
    GmailApp.sendEmail('<<YOUR EMAIL ADDRESS>>', data.subject + '[CONTACT FORM]', '', {
      name: 'Contact Form',
      htmlBody: html.evaluate().getContent(),

    return {
      code: 'success',
      msg: "Thanks for contacting me! I can't wait to talk about #EdTech with you!",
  } catch (err) {
    return {
      code: 'danger',
      msg: 'Something went wrong! Technology is not always pretty!',


<!DOCTYPE html>
    <base target="_top" />
      You are being contacted from your website by <b><?= name ?></b> at <b><?= email ?></b>

      Time sent:
        ><?= new Date().toDateString() ?>
        <?= new Date().toTimeString() ?></b

      Subject: <b><?= subject ?></b>

    <p><?= body ?></p>

jordan rhea wearing a hoodie
Written by jordan rhea Building tools and connecting systems