Sub topic 12
Confirming Subscribers with Double Opt-in
This chapter assumes you can read basic HTML and JavaScript, know what an email service provider (ESP) does, and have read the chapter on consent and privacy rules. Here you will learn what double opt-in is, what it costs and what it gains, how the flow works internally, and how to build the confirmation step yourself.
What double opt-in is
Single opt-in adds an address to your list as soon as someone submits the form. Double opt-in adds a second step. After the form is submitted, you send a confirmation email containing a unique link. The address becomes an active subscriber only when the recipient clicks that link.
The confirmation click proves two things that a form submission does not:
- The address is real and the person can read mail sent to it.
- The owner of the address, not someone else, asked to be subscribed.
The second point matters most. Anyone can type another person's address into your form, by mistake or on purpose. Without confirmation, you would send marketing email to a person who never asked for it.
The flow
A subscriber moves through three states: unconfirmed (pending), confirmed, and expired. The diagram shows the transitions.
In sequence, the flow looks like this:
- The visitor submits the form.
- The server stores the address with status
pending, a random token, and a creation time. - The server sends a confirmation email with a link such as
https://example.com/confirm?token=.... - The visitor clicks the link. The server checks the token, marks the record
confirmed, and records the time, IP address and the wording of the consent they saw. - The visitor lands on a "You're subscribed" page. The welcome email goes out.
Only step 5 should trigger the welcome email. Sending it earlier defeats the purpose of confirming.
Trade-offs
Double opt-in is not free. Some people never open the confirmation email, and some never see it because it lands in spam. Typical drop-off is a meaningful share of sign-ups, so your list grows more slowly than it would with single opt-in.
| Factor | Single opt-in | Double opt-in |
|---|---|---|
| List growth speed | Faster | Slower, because some people never confirm |
| Invalid or mistyped addresses | Enter the list | Filtered out |
| Spam-trap and bot addresses | Can enter the list | Mostly filtered out |
| Proof of consent | Weak | Strong, with a timestamped confirmation |
| Spam complaints | Higher risk | Lower risk |
| Engagement per subscriber | Usually lower | Usually higher |
The smaller list is usually the healthier one. Mail providers judge you on bounces, complaints, and engagement. A list full of mistyped or unwanted addresses damages your sender reputation, which lowers inbox placement for everyone, including your real subscribers.
When it is required or advisable
The law varies by country, so check the rules that apply to your audience.
- Some countries and regulators effectively expect it. Germany is the usual example: courts have held that the sender must be able to prove consent, and a confirmed opt-in is the accepted way to do that.
- Under the GDPR, you must be able to demonstrate consent. Double opt-in is not strictly mandated, but the confirmation record is strong evidence.
- In the United States, the CAN-SPAM Act does not require it. Many senders use it anyway for list quality.
- Some ESPs enforce it on their own terms. Check your provider's policy.
If you collect addresses in a way that invites typos or abuse, such as pop-ups with a single field or giveaways that attract bots, lean toward double opt-in.
Building the confirmation step
The sign-up form from the HTML chapter needs no changes. The work happens on the server. Most ESPs do this for you, but it helps to know what they do. The following Node.js sketch uses Express and an in-memory store. It is complete enough to run, but a real system needs a database and a real mail sender.
import express from 'express';
import crypto from 'node:crypto';
const app = express();
app.use(express.urlencoded({ extended: false }));
const TOKEN_TTL_MS = 48 * 60 * 60 * 1000; // 48 hours
const subscribers = new Map(); // email -> record
const tokens = new Map(); // token hash -> email
function hashToken(token) {
return crypto.createHash('sha256').update(token).digest('hex');
}
async function sendMail(to, subject, text) {
// Replace with your ESP or SMTP client.
console.log(`To: ${to}\nSubject: ${subject}\n\n${text}\n`);
}
app.post('/subscribe', async (req, res) => {
const email = String(req.body.email || '').trim().toLowerCase();
if (req.body.website) return res.status(204).end(); // honeypot filled
if (req.body.consent !== 'yes') return res.status(400).send('Consent required');
if (!/^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(email)) {
return res.status(400).send('Invalid email');
}
const existing = subscribers.get(email);
if (existing && existing.status === 'confirmed') {
// Same response as a new sign-up, so the form does not reveal who is subscribed.
return res.send('Check your inbox to confirm.');
}
const token = crypto.randomBytes(32).toString('hex');
tokens.set(hashToken(token), email);
subscribers.set(email, {
status: 'pending',
createdAt: Date.now(),
consentText: 'I agree to receive the weekly newsletter',
ip: req.ip,
});
await sendMail(
email,
'Please confirm your subscription',
`Confirm here: https://example.com/confirm?token=${token}\n` +
'If you did not request this, ignore this email.'
);
res.send('Check your inbox to confirm.');
});
app.get('/confirm', (req, res) => {
const key = hashToken(String(req.query.token || ''));
const email = tokens.get(key);
const record = email && subscribers.get(email);
if (!record) return res.status(400).send('Invalid or used link');
if (Date.now() - record.createdAt > TOKEN_TTL_MS) {
tokens.delete(key);
return res.status(410).send('This link has expired. Please sign up again.');
}
record.status = 'confirmed';
record.confirmedAt = Date.now();
tokens.delete(key); // single use
res.send('You are subscribed.');
});
app.listen(3000);Several design choices in this code are deliberate:
- Random, unguessable tokens.
crypto.randomBytes(32)gives 256 bits of randomness. A sequential ID or a hash of the email address could be guessed, which would let someone confirm addresses they do not own. - Stored as a hash. Only the hash of the token is kept, so a leaked database does not hand out working confirmation links.
- Expiry. Old tokens stop working after 48 hours, which limits abuse of stale links.
- Single use. The token is deleted after confirmation.
- Identical responses. The form says the same thing whether or not the address is already on the list. Otherwise it leaks who is subscribed.
- Consent evidence. The record stores the consent wording, time, and IP address. This is the evidence regulators ask for.
Writing the confirmation email
The confirmation email is the most important message you will send, because every subscriber must act on it. A few rules make it work:
- Send it immediately. The visitor is still on your site or has just left. A delay of ten minutes loses many of them.
- Use a clear subject line, such as "Confirm your subscription to Weekly Notes". Avoid clever wording.
- Make one button or link the obvious action.
- Say what they are confirming and where they signed up. Add a line telling them to ignore the message if they did not sign up.
- Send from the same name and address the newsletter will use, so they recognize it later.
- Keep it plain. Heavy images and many links raise the chance of spam filtering.
On the form's success message, or on the thank-you page, tell the visitor to check their inbox, name the sender, and mention the spam folder. Many drop-offs happen because people finish the form and never realize that a second step exists.
If you offer a lead magnet, decide when it is delivered. Delivering it on the confirmation page, or in the welcome email, gives people a reason to complete the step.
Handling the awkward cases
Real flows have edge cases that the simple diagram hides.
- Unconfirmed addresses. Decide how long they stay pending. A common policy is to send one reminder after one or two days and delete the record after a week. Do not send newsletters to pending addresses.
- Repeat submissions. If someone submits twice, resend a confirmation, but rate-limit it. Otherwise an attacker can use your form to flood a victim's inbox with confirmation emails.
- Expired tokens. Show a clear message and let the person request a new link without retyping everything.
- Confirmed addresses submitting again. Do not send another confirmation. Respond as if nothing special happened.
- Pop-up sign-ups. Make sure the pop-up's success state explains that an email is on its way, because the dialog closes quickly and visitors move on.
- Imported lists. Double opt-in applies to people who sign up through your forms. An imported list needs its own proof of consent. Importing addresses and sending a confirmation request to them does not make them valid subscribers if they never agreed to hear from you.
Measuring the extra step
Double opt-in adds a second conversion rate to track:
- Form conversion rate = submissions / visitors who saw the form.
- Confirmation rate = confirmed / submitted.
- Net conversion rate = confirmed / visitors who saw the form.
Compare variants on net conversion, not on submissions. A form with a more enticing offer can attract more submissions but fewer real subscribers. If your confirmation rate is low, investigate before changing the form: check that the email arrives, check the spam folder, check the subject line, and check that the link works on mobile.
Exercise
A site gets 2,000 visitors who see its sign-up form. 200 submit it, and 140 click the confirmation link. What are the form conversion rate, confirmation rate, and net conversion rate? Which one should you use to compare two versions of the form?
Show answer
Form conversion rate is 200 / 2,000 = 10%. Confirmation rate is 140 / 200 = 70%. Net conversion rate is 140 / 2,000 = 7%. Use net conversion rate to compare versions, because a version that raises submissions but lowers confirmations may produce fewer actual subscribers.
Exercise
Why should a confirmation token be random and single-use, and why might a plain GET confirmation link confirm a subscription by mistake?
Show answer
A random token cannot be guessed, so nobody can confirm an address they do not control. Single use stops a link from being reused after it has served its purpose. Some email security scanners fetch every link in a message, so a GET link can be opened automatically and confirm the subscription before the owner acts. A confirmation page with a POST button avoids this.