Plugin to extend the use of the Contact Form plugin by logging records of all emails sent from the CMS
To install Contact Form Logs, follow these steps:
- Download & unzip the file and place the
contactformlogs
directory into yourcraft/plugins
directory - -OR- do a
git clone ???
directly into yourcraft/plugins
folder. You can then update it withgit pull
- -OR- install with Composer via
composer require /contactformlogs
- Install plugin in the Craft Control Panel under Settings > Plugins
- The plugin folder should be named
contactformlogs
for Craft to see it. GitHub recently started appending-master
(the branch name) to the name of the folder for zip file downloads.
Contact Form Logs works on Craft 2.4.x and Craft 2.5.x.
This plugin is used to log submissions from the Craft Contact Form.
It also creates an area in the CMS for viewing sent messages and provides variables for browsing messages in the front-end.
Contact Form Logs provides the ability to log multiple forms on a site by adding an optional form
field.
You can change the name/label for Contact Form Logs within the Plugin settings by updating the Known As
field.
Visting the Contact Form Logs area of the CMS will provide a list of messages posted through the Contact Form plugin.
These can be filtered by clicking on the form name shown in the Form column.
Message details can be viewed by clicking on the email subject.
There are two additional functions that can be used.
- You can add a 'form' input to your forms which means you can differentiate the logs available for different forms on your site
- There are two new fields available:
firstName
andlastName
if you need to capture these separately (rather than simplyfromName
). Contact Form Logs will concatenate these for the purposes of the Contact Form plugin but store these as separate fields.
You can use {% set logs = craft.contactformlogs.logs( ) %}
to fetch all message logs available or filter these by defining a criteria to filter against, for example {% set vars = { form: 'Contact Form } %}
then {% set logs = craft.contactformlogs.logs( vars ) %}
. For each log entry the following variables are available:
log.form
Stringlog.fromName
Stringlog.fromEmail
Stringlog.toEmail
Stringlog.subject
Stringlog.message
Stringlog.htmlMessage
HTML Stringlog.messageFields
JSON object-
log.status
String (eitherholding
orsent
) log.timestamp
- a DateTime object
The Contact Form plugin doesn't have a post send hook so the logs are recorded in a two-step process.
On the contactForm.beforeSend
event the plugin detects a submisssion from the Contact Form plugin, modifies any fields (eg merges firstName and lastName into a single fullName field) and stores the message with a status of holding.
Then, on the email.onSendEmail
event the plugin checks to see if a message has been logged in the last ten minutes that matches the status and sender email and changes any records to sent
as well as update the record for the subject of the message (this is to deal with the Contact Form dynamically generates subject if variables are present).
- Logs sorting
- Abstract
contactForm.beforeSend
andemail.onSendEmail
hooks into a separate service
Brought to you by @cole007
Log Icon via Noun Project from Ben Davis, RO