Custom notification email content

The notification content can be customized at Edit Form → Settings → Notifications then going to the settings (cog icon) for the notification then entering the content into the Message setting.

This is the default layout HTML for email notifications. It can be reused for custom notifications.

12
3
4
5
6
7
8
<table width="100%" cellpadding="10" cellspacing="0" border="0" style="background: #ffffff; border-bottom: 1px solid #d4d4d4; box-shadow: 0 2px 7px 0 rgba(0, 0, 0, 0.07);"><tr bgcolor="#efefef"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold; color: #282828; border: 1px solid #d4d4d4; border-bottom: 0;">
Label
</td></tr>
<tr bgcolor="#fcfcfc"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #282828; line-height: 130%; border: 1px solid #d4d4d4; border-bottom-color: #fff;">
Entry
</td></tr>
</table>
<table width="100%" cellpadding="10" cellspacing="0" border="0" style="background: #ffffff; border-bottom: 1px solid #d4d4d4; box-shadow: 0 2px 7px 0 rgba(0, 0, 0, 0.07);">
<tr bgcolor="#efefef"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 15px; font-weight: bold; color: #282828; border: 1px solid #d4d4d4; border-bottom: 0;">
Label
</td></tr>
<tr bgcolor="#fcfcfc"><td valign="top" style="font-family: Helvetica, Arial, sans-serif; font-size: 14px; color: #282828; line-height: 130%; border: 1px solid #d4d4d4; border-bottom-color: #fff;">
Entry
</td></tr>
</table>

For more advanced or complex email content (for example with conditional parts) the content needs to be created in PHP code.

Step 1

Create a plugin for the custom code, then add the code below to the quform-custom-code.php file.

12
3
4
5
add_action('quform_pre_send_notification_1_1', function ($mailer, Quform_Notification $notification, Quform_Form $form) {    ob_start();
    include __DIR__ . '/email-content.php';
    $mailer->Body = ob_get_clean();
}, 10, 3);
add_action('quform_pre_send_notification_1_1', function ($mailer, Quform_Notification $notification, Quform_Form $form) {
    ob_start();
    include __DIR__ . '/email-content.php';
    $mailer->Body = ob_get_clean();
}, 10, 3);
  • On line 1, replace 1_1 with the notification unique ID
1
2
3
4
5
6
function my_custom_notification_content($mailer, Quform_Notification $notification, Quform_Form $form) {
    ob_start();
    include dirname(__FILE__) . '/email-content.php';
    $mailer->Body = ob_get_clean();
}
add_action('quform_pre_send_notification_1_1', 'my_custom_notification_content', 10, 3);
function my_custom_notification_content($mailer, Quform_Notification $notification, Quform_Form $form) {
    ob_start();
    include dirname(__FILE__) . '/email-content.php';
    $mailer->Body = ob_get_clean();
}
add_action('quform_pre_send_notification_1_1', 'my_custom_notification_content', 10, 3);
  • On line 6, replace 1_1 with the notification unique ID

Step 2

Create a file named email-content.php and put it into the same folder as the quform-custom-code.php file created in Step 1. In the email-content.php put the custom email content in HTML and PHP. See this page for getting form data, below is an example.

1
2
3
4
<h2>Submitted form data</h2>
<p>Name: <?php echo $form->getValueHtml('quform_1_3'); ?></p>
<p>Email: <?php echo $form->getValueHtml('quform_1_4'); ?></p>
<p>Message: <?php echo $form->getValueHtml('quform_1_5'); ?></p>
<h2>Submitted form data</h2>
<p>Name: <?php echo $form->getValueHtml('quform_1_3'); ?></p>
<p>Email: <?php echo $form->getValueHtml('quform_1_4'); ?></p>
<p>Message: <?php echo $form->getValueHtml('quform_1_5'); ?></p>
  • Replace 1_3, 1_4 and 1_5 with the unique ID of the element to display the value for

Conditional blocks

To only show a field if the value is not empty you can use an if statement.

123
<?php if ($form->getValueHtml('quform_1_6') !== '') : ?>    <p>Phone: <?php echo $form->getValueHtml('quform_1_6'); ?></p><?php endif; ?>
<?php if ($form->getValueHtml('quform_1_6') !== '') : ?>
    <p>Phone: <?php echo $form->getValueHtml('quform_1_6'); ?></p>
<?php endif; ?>
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy