Contacts

A public contact form at /contact and the inbox it fills at /admin/contacts. Messages are mailed to the admins with a copy to the sender, and a reply from the inbox goes out by mail.

The contact form as a guest sees it: name, email, a subject select and a message box under the user shell's signed-out header with Sign in and Register
/contact, signed out.

What it adds

FilePurpose
app/Models/ContactSubmission.phpName, email, subject, message, status, IP, reply and reply timestamp
database/factories/ContactSubmissionFactory.phpFactory with a replied state
database/migrations/*_create_contact_submissions_table.php
app/Livewire/ContactForm.php and its viewThe public form, in the user shell
app/Livewire/Admin/Contacts/ContactList.php and its viewThe inbox
app/Mail/ContactSubmittedMail.php, ContactConfirmationMail.php, ContactReplyMail.php, resources/views/mail/contact/*The three mailables and their markdown views

Install

php artisan ui-kit:install-module contacts

No Composer packages. Mail goes through your queue, so run php artisan queue:work unless QUEUE_CONNECTION=sync, and set MAIL_FROM_ADDRESS.

What the installer changes

  • Adds /contact between the public-routes markers in routes/ui-kit-user.php, the group open to guests, and the inbox route between the markers in routes/admin.php.
  • Adds a Contacts entry with the unread_contacts badge in config/admin.php. The kit's default badge resolver fills it from ContactSubmission::unread() (unread and not archived), so it works with no code.
  • Runs the migration.

Routes

RouteName
GET /contactcontact
GET /admin/contactsadmin.contacts.index

If your app already has a /contact page, rename the kit's path in routes/ui-kit-user.php, or delete the line; Troubleshooting has the details.

The form

Name, email, a subject and a message, for guests and signed-in users alike; a signed-in user's name and email are filled in. The subjects are a list in config/ui-kit.php, five neutral labels to start with:

'contacts' => [
    'subjects' => [
        'General question',
        'Account or billing',
        'Problem report',
        'Feature suggestion',
        'Something else',
    ],
],

The chosen label is stored as the message's subject and is checked against that list. The message must be 10 to 5,000 characters. On success the message is saved with the sender's IP, the admins get a ContactSubmittedMail (replying to it writes to the sender) and the sender a ContactConfirmationMail with a copy of what they wrote, and the form gives way to a thank-you with a Send another button.

Two guards: a honeypot field, visually hidden, out of the tab order and never autofilled, which a form-filling bot fills and a person never sees (a filled one shows the same thank-you and saves nothing); and three messages an hour per IP address, counted only once a message passes validation, so a typo never uses up an attempt. Behind a proxy the limit needs trusted proxies, or every visitor shares one address.

The inbox

The contact inbox: stat tiles for total, unread, replied and archived, a search field and a status filter over a table of messages with a select column
/admin/contacts.

Four stat tiles count the messages in the inbox, unread, replied and archived. A search field (name, email or subject) and a status filter sit over a table: a select column, the message (subject, then sender and address), a status badge from ContactSubmission::statusTone(), when it arrived, and an Open button. Selecting anything shows a bulk bar with Mark read, Mark unread, Archive and Delete.

Open shows the message in a ds::modal, with a reply box and the per-message actions. Send Reply saves the reply, marks the message replied and sends a ContactReplyMail to the sender: subject "Re: …", the reply first, then their message quoted. The inbox says "Reply sent to …", or, when the mail fails, "Reply saved, but the email failed: …" with the reason, and the reply stays saved either way.

Archiving sets archived_at rather than a status: an archived message leaves the inbox and its counts, and shows under the Archived filter, where it can be unarchived.

Mail

MailableSent whenTo
ContactSubmittedMailSomeone sends the formThe admins; replying to it writes to the sender
ContactConfirmationMailThe sameThe sender, with a copy of the message
ContactReplyMailAn admin replies in the inboxThe sender

"The admins" are UiKit::admins(), or the addresses in UI_KIT_ADMIN_ADDRESSES (Customising). The doctor's contacts mail views published row checks every class and view.

With support tickets

When the support-tickets module is also installed, each message gets a Copy to Ticket button that opens a ticket for the sender with the message as the first reply.

Removing

Delete the model, factory, both Livewire components and their views, the mailables and resources/views/mail/contact/, remove the route lines from routes/ui-kit-user.php and routes/admin.php and the nav entry between their markers, drop contact_submissions, and remove contacts from installed_modules.

Was this page helpful?