Add a form to contact author?

Is it possible to implement a form on a post page to contact the author?

Better still, if the member is logged in, is it possible to have a button (eg, ‘contact me’) which could automatically email the author the contact information for the member?

Sounds so simple, but I have a sneaky suspicion it isn’t!

Hey @dosandco :wave:
This is definitely possible, and we’ve even got a tutorial on our site that covers the majority of how to do it:

Adding the authors email is the interesting part. User emails aren’t reachable with handlebars to prevent security risks. However with a bit of JavaScript you can drop the authors into the form in the tutorial.

After you’ve followed the tutorial add the following piece of code right after the form HTML:

<script>
if (typeof authorEmail !== 'undefined') {
  document
    .querySelector("form.contact-form")
    .setAttribute("action", `https://formspree.io/${authorEmail}`);
}
</script>

Then head over to a post in Ghost admin and open the post setting panel. Drop the following code into the Code Injection Post header:

<script>var authorEmail = "the@author.email";</script>

You’ll need to replace the@author.email with the actual authors email address. If the line above isn’t applied to the Code Injection header of the post then form submissions will be sent to the email set in the HTML.

I hope this makes sense. Any questions just ask!