Custom email content

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

This guide is for advanced usage, you can modify the notification email content inside the Form Builder at Settings → Email → Customize email content

This guide will outline how to build the notification email content at the PHP level, which is useful if you need to display output from WordPress functions or variables and other complex logic in the email.

Step 1

Add the following code to your theme functions.php file (or create a plugin for it).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function my_customize_email($mailer, $form, $attachments)
{
    // Get the new email content from the file email-content.php
    ob_start();
    include dirname(__FILE__) . '/email-content.php';
    $content = ob_get_clean();
 
    // Set the email content
    $mailer->msgHTML($content);
 
    // You must return the $mailer object
    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_customize_email', 10, 3);
function my_customize_email($mailer, $form, $attachments)
{
    // Get the new email content from the file email-content.php
    ob_start();
    include dirname(__FILE__) . '/email-content.php';
    $content = ob_get_clean();

    // Set the email content
    $mailer->msgHTML($content);

    // You must return the $mailer object
    return $mailer;
}
add_filter('iphorm_pre_send_notification_email_1', 'my_customize_email', 10, 3);

Step 2

Create a file named email-content.php and enter the email content, in HTML format. To get access to submitted form data you will need the unique ID of each of the form elements that you want to use, see Finding the unique element ID. To find out what the return values are for different element types, see Getting form values page. You can then display the value using the code below. Replace iphorm_X_X with your form element unique ID.

1
<?php echo $form->getValueHtml('iphorm_X_X'); ?>
<?php echo $form->getValueHtml('iphorm_X_X'); ?>

An example of email-content.php is shown below.

1
2
3
4
5
<?php echo $form->getValueHtml('iphorm_1_1'); ?> has submitted a form on your website.
<h2>Submitted form data</h2>
Name: <?php echo $form->getValueHtml('iphorm_1_1'); ?><br />
Email: <?php echo $form->getValueHtml('iphorm_1_2'); ?><br />
Message: <?php echo $form->getValueHtml('iphorm_1_3'); ?>
<?php echo $form->getValueHtml('iphorm_1_1'); ?> has submitted a form on your website.
<h2>Submitted form data</h2>
Name: <?php echo $form->getValueHtml('iphorm_1_1'); ?><br />
Email: <?php echo $form->getValueHtml('iphorm_1_2'); ?><br />
Message: <?php echo $form->getValueHtml('iphorm_1_3'); ?>

Step 3

Upload the file email-content.php to the same folder as the file containing the code from Step 1.

See also

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy