Skip to content

How to build a quote request form in iOS with SwiftUI

A SwiftUI inquiry form with service and budget pickers and a deadline that emails you every request and sends the customer an automatic confirmation – no backend.

Updated:

This tutorial builds a quote request form in SwiftUI with native pickers: service, budget and a deadline, plus a description. You receive a structured email; the customer receives an automatic confirmation.

You need: a free Frontmail account, an Xcode project with SwiftUI and about twenty minutes.

1. Connect your mailbox and create the templates

  1. Email services → Add service: connect your mailbox or provider, Make default, Verify & save.
  2. Templates → From gallery → Quote request (category Business) → Use template.
  3. From gallery → Auto-reply: thanks for your message → Use template; set defaults for company_name and response_time, then select it in the quote template under Settings → Delivery → Auto-reply template.

The quote template needs name, email, service and details; phone, company, budget and deadline (YYYY-MM-DD) are optional. service and budget accept only the values on the Parameters tab – use the same strings in the app.

2. Allow mobile apps and turn on the CAPTCHA

  • Security → Mobile apps → Allow mobile apps → Save.
  • Quote template → Settings → Protection → Require CAPTCHA (Turnstile) – Frontmail’s shared mobile widget, no keys needed.

3. Add the package

File → Add Package Dependencies… → https://github.com/frontmail-dev/frontmail-swift → add Frontmail to your target, and copy TurnstileView from the Turnstile section of the iOS SDK documentation.

4. Build the form

import SwiftUI
import Frontmail

let frontmail = try! Frontmail(publicKey: "pk_…")

let services = ["Website", "E-shop", "Mobile app", "Consulting", "Other"]
let budgets = ["Under $5k", "$5k–20k", "$20k–50k", "Over $50k"]

struct QuoteRequest: Encodable {
    let name: String
    let email: String
    let service: String
    let budget: String?   // nil is left out of the email
    let deadline: String? // YYYY-MM-DD
    let details: String
}

struct QuoteView: View {
    @State private var name = ""
    @State private var email = ""
    @State private var service = services[0]
    @State private var budget = ""
    @State private var hasDeadline = false
    @State private var deadline = Date()
    @State private var details = ""
    @State private var widget: Turnstile.Widget?
    @State private var token: String?
    @State private var resetID = 0
    @State private var info = ""

    var body: some View {
        Form {
            Section {
                TextField("Name", text: $name)
                TextField("Email", text: $email)
                    .keyboardType(.emailAddress)
                    .textInputAutocapitalization(.never)
            }
            Section {
                Picker("What do you need?", selection: $service) {
                    ForEach(services, id: \.self) { Text($0) }
                }
                Picker("Budget", selection: $budget) {
                    Text("Not sure yet").tag("")
                    ForEach(budgets, id: \.self) { Text($0) }
                }
                Toggle("I have a deadline", isOn: $hasDeadline)
                if hasDeadline {
                    DatePicker("Deadline", selection: $deadline, in: Date()..., displayedComponents: .date)
                }
                TextField("Project details", text: $details, axis: .vertical)
                    .lineLimit(4...8)
            }
            if let widget {
                TurnstileView(widget: widget, size: .flexible, resetID: resetID) { event in
                    if case let .token(t) = event { token = t } else { token = nil }
                }
                .frame(height: Turnstile.Size.flexible.recommendedHeight)
            }
            Button("Request a quote") { Task { await send() } }
                .disabled(token == nil)
            Text(info)
        }
        .task { widget = try? await Turnstile.widget(client: frontmail) }
    }

    private func send() async {
        guard let widget, let token else { return }
        defer { self.token = nil; resetID += 1 } // a token works only once
        let request = QuoteRequest(
            name: name,
            email: email,
            service: service,
            budget: budget.isEmpty ? nil : budget,
            deadline: hasDeadline ? deadline.formatted(Date.ISO8601FormatStyle(timeZone: .current).year().month().day()) : nil,
            details: details
        )
        do {
            _ = try await frontmail.send(
                templateID: "tpl_…",
                params: request,
                options: SendOptions(turnstileToken: token, turnstileKey: widget.turnstileKey)
            )
            info = "Thanks! We’ve emailed you a confirmation."
        } catch let error as FrontmailError {
            info = error.message
        } catch {
            info = error.localizedDescription
        }
    }
}

Optional properties that are nil aren’t encoded at all, so empty rows never show up in the email.

5. Test it

Send a request with your own address as the customer email: you receive the request and the confirmation, and both appear in History.

A request with its confirmation uses two credits. If credits run out, requests are accepted as .held and go out automatically after a top-up.

Next steps

  • Turn on Contact collection in the template settings to build a list of everyone who asked for a quote.
  • Attach a brief or photos with SendOptions(attachments: [.data(…)]) – see the SDK documentation.
All tutorials