ForgeCrowdBookWe don't sell the fish – we give you the rod.

Contact Form and Newsletter

Two things almost every website needs: a way for visitors to write to you, and a way for you to write to everyone who wants to hear from you. In WordPress that is two plugins, often from two companies, each with its own settings page and its own idea of privacy. In ForgeCMS it is two modules that know each other.

Goal

By the end of this chapter you can:

  • put a contact form with your own fields on any page,
  • run a newsletter with proper double opt-in,
  • write and send a mailing,
  • know what the modules store, and what they do not.

First: mail

Both modules send mail, so your server has to be able to send it, and the mail must not land in spam. That takes a mail program on the server and three entries in your domain's DNS (called SPF, DKIM and PTR). It sounds technical; for the AI it is routine:

Please set up sending mail from my server for mybakery.com, so that mails
from the contact form do not end up in spam (SPF, DKIM, PTR). Tell me which
DNS entries I have to add.

You add the DNS entries it gives you in your domain's settings, the same place as the A record in chapter 3. Then ask it to send you a test mail.

The contact form

The form is described once in app.sml and placed on a page with one element. A typical request:

Please add a contact form on /contact with name, email, a choice
"Order / Catering / Other", a message, and a box to sign up for the newsletter.
Messages should go to hello@mybakery.com.

What the AI writes into app.sml:

Contact {
    to: "hello@mybakery.com"
    Field { name: "name"  type: "text"     label: "Name"    required: true }
    Field { name: "email" type: "email"    label: "Email"   required: true }
    Field { name: "topic" type: "radio"    label: "Topic"   options: "Order, Catering, Other" }
    Field { name: "text"  type: "textarea" label: "Message" required: true }
    Field { name: "news"  type: "newsletter" label: "Yes, send me the newsletter" }
}

And on the page:

ContactForm { submit: "Send" }

The contact form

Field types:

Type Is
text one line
email an email address, checked
tel a phone number
textarea a longer text
checkbox one box (with required: true, e.g. "I agree to …"), or several with options
radio one of several options
select a drop-down list of options
newsletter the sign-up box; only shown when the newsletter is on

Labels and options can be translated: label_de, options_de.

What happens when someone sends it: the message goes to you by mail. When you answer, your reply goes straight to the visitor. The message is not stored on the server; there is nothing to leak, and nothing to delete later.

Spam: the form has three protections built in. A hidden field that only bots fill in, a time stamp (a post sent faster than three seconds after the page opened is dropped, because people do not type that fast), and a limit of ten posts per visitor per hour. In practice this keeps the inbox clean without any "click all the traffic lights" puzzle.

The newsletter

Please add a newsletter. I write it (me@mybakery.com), it is called
"Bakery News", and the privacy policy is at /privacy.

In app.sml:

Newsletter {
    admins:  "me@mybakery.com"
    privacy: "/privacy"
    name:    "Bakery News"
}

People can sign up in two places: with the box in the contact form, or with a sign-up box anywhere:

NewsletterForm { }

Double opt-in: after signing up, people get a mail with a link and are only on the list after they confirm. This is required by law in the EU, and it keeps strangers from signing up other people. Unconfirmed addresses are deleted after 30 days.

Writing a mailing: open https://mybakery.com/newsletter/admin. You log in with a link sent to your admin address. Then:

  1. Write the subject and the text, in Markdown like your pages.
  2. Look at the preview.
  3. Send yourself a test mail and read it on your phone.
  4. Tick the confirmation box and press Send.

The mails go out one by one in the background, one per second by default; the page shows the progress. If the server restarts in between, it continues where it stopped.

Every mail has an unsubscribe link, and mail programs show their own "unsubscribe" button too. A click removes the address for good.

What it does not do: no tracking pixels, no counting who opened what, no rewriting of links to measure clicks. You will not know your "open rate". Your readers will thank you.

What is stored

Module Stores
Contact form nothing; messages are only mailed
Newsletter the list of addresses with language and the date of confirmation, as a small file on your server

Mention both in your privacy policy. The AI can write a first draft, but have someone who knows the law of your country look at it.

Pitfalls

  • No mails arrive: first check spam, then ask the AI to send a test mail and look at the mail log. Missing DNS entries are the usual reason.
  • The newsletter box does not appear in the form: the Newsletter { } block is missing in app.sml.
  • "Please send it again": the form was open for more than a day, or the server restarted in between. Visitors just press send again; their text is kept.
  • Writing the newsletter in Word and pasting it: it comes out messy. Write plain text with Markdown marks, or paste and ask the AI to clean it up.

What you learned

  • Both modules need mail on the server; the AI sets it up, you add the DNS entries.
  • Contact { Field ... } in app.sml describes the form; ContactForm { } shows it. Messages are mailed, never stored.
  • Newsletter { } with double opt-in; NewsletterForm { } or the box in the contact form to sign up.
  • Mailings are written in Markdown at /newsletter/admin, with preview and test mail, and go out without any tracking.