Sitemap
Jasmine Liu

Jasmine Liu

Everything in the world is interconnected.

Coding Diary

Sending email from static page hosted on Github Pages

3 min readNov 20, 2017

--

Press enter or click to view image in full size

So you’ve decided that you wanted to use a website hosted on Github, whether it’s for your portfolio, projects or something else spectacular.

The wonderful thing about a Github Page is that you only need to make your local folder a git repository and push up your code. From there, your website is automatically updated. It’s as easy as that! For more info on Github Pages, here’s the link; or if you would like an overview on how to setup your Github, checkout my tutorial here!

But as far as free web hosts go, there are certain limitations, and one of them for Github Pages is the lack of mailing features. I discovered this when making a page of my own. I was eager to implement a form where visitors on my website can send a message directly to my email. Here’s a snapshot of the contact form provided by my static page web template:

Unfortunately, there is no actual way for this form to work on Github…not without external help. This is because most backend stuff needed for mailing is written in PHP, which is not supported by Github Pages (and there’s several other factors as well). There are many form submission tools out there that can make this form work, such as mandrillapp, sendgrid, etc. However, the one that worked like a charm and the one I’ll show you is formspree.

~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

Get Jasmine Liu’s stories in your inbox

Join Medium for free to get updates from this writer.

Formspree doesn’t require PHP, JavaScript or sign up, making it the perfect place to send HTML forms for static websites. It is immensely easy to use. Refer to the steps below. This is a sample code of what a form might look like after formspree changes:

<form action="https://formspree.io/your@email.com"
method="POST"
>
<input type="text" name="name">
<input type="email" name="_replyto">
<input type="submit" value="Send">
</form>

That is a rather simple form. Below is what my code actually looked like for the contact form in the previous picture:

<form action="https://formspree.io/jasliu2012@gmail.com" method="post" id="contact-form" class="contact-form margin-9 no-margin-bottom no-margin-rl">
<input type="text" placeholder="* Your Name" name="name" id="name" class="required">
<input type="text" placeholder="* Your Email" name="email" id="email" class="required email">
<textarea placeholder="* Your Message" name="message" id="message" class="required"></textarea>
<button id="submit" type="submit" class="btn btn-medium background-black text-white">Send Message</button>
</form>
  1. In your text editor, go to the forms section of your page and change the form’s action to this https://formspree.io/your@email.com . Replace your@email.com with your real email.
  2. Make sure all <input>, <select>, and <textarea> elements inside your form have a name attribute, or else those fields will come empty when you get your email.
  3. Save your text editor and push up your code. Sometimes it takes a minute or two for Github Pages to update your website.
  4. Go to your website and submit the form once (with or without filled in info).
  5. Now go to your email and you’ll see a confirmation email. If you by chance have the same form in multiple URLs on your site, you’ll need to confirm mulitple times.
  6. And you’re set! From now on, when someone submits that form, Formspree will forward you the data as email.

~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~

If you found this tutorial helpful, clap below! :)

Credits: Formspree, Stack Overflow

--

--

Jasmine Liu
Jasmine Liu

Written by Jasmine Liu

Everything in the world is interconnected.