Contact Form has been completely rebuilt for Craft 6.x! We are using this release to show off some cool new Laravel features, like validation, routing, events, and mailers.
- Contact Form now requires Craft CMS 6.0 or later and PHP 8.5 or later, and runs natively on Craft 6 without the
craftcms/yii2-adapterpackage. See UPGRADE.md. - Plugin settings can now be overridden from
config/craft/contact-form.php. Runphp artisan vendor:publish --tag=contact-formto create it. - Added the
rateLimitsetting, which limits how many submissions each IP address can make per minute. Rate-limited submissions get an error flash (or a429response for Ajax requests). - Notifications are now sent to all of the configured recipients at once, rather than as one message per recipient.
- You now have full control over the contents of email notifications, via Utilities → System Messages.
- Additional fields (like
message[referralSource]) can now be validated with rules defined inconfig/craft/contact-form.php. allowedMessageFieldsnow rejects unlistedmessagesub-fields with a validation error, for both lists of names and maps of rules.message[body]is always allowed.- Fields can now be nested (i.e.
message[referral][primary][name]) and are output recursively in notifications. - Suppressed notifications and failures with the mail driver have been consolidated into a single error state. Spam submissions still appear to succeed, and are logged instead of sent.
Deprecated
- The
prependSubjectsetting is no longer necessary, as the notification subject can be customized (and localized!) via the System Messages utility.
Removed
All classes in the craft\contactform\* namespace have been removed. Here are the most relevant changes:
craft\contactform\models\Submissionwas removed in favor of a ruleset that validates the plain request data.- The
craft\contactform\Mailerclass has been eliminated, in favor of building the message directly in the controller. The sender’s name is compiled byCraftCms\ContactForm\Submission\Sender, and the notification body/summary is compiled byCraftCms\ContactForm\Submission\Summary. craft\contactform\Mailer::EVENT_BEFORE_SEND(andcraft\contactform\events\SendEvent) must be replaced with a listener forCraftCms\ContactForm\Events\MessageSending.- Set
$event->isSpam = trueor$event->isValid = falseto prevent sending. - You can access all of the previous data via the single
CraftCms\Cms\SystemMessage\Mailables\SystemMessageMailable $messageevent property (i.e.$message->toor$message->variables).
- Set
craft\contactform\Mailer::EVENT_AFTER_SEND(andcraft\contactform\events\SendEvent) must be replaced with a listener forCraftCms\ContactForm\Events\MessageSent.- Validation rules should be added via configuration (in
config/craft/contact-form.php), or in a listener (for theCraftCms\Cms\Validation\Events\ValidationRulesResolvingevent).