Send to friend form

This guide will show you how to make a Send To Friend form that will send an email to the given email address and include a link to the form page.

Step 1 – Add the form to a page on your site

I have created an example form below, you can copy and paste this into your site to get started. Note that I have change the form action attribute to point to a different process file process-send-to-friend.php we will cover that in Step 2. You will also need the links to the Quform CSS and JS files on the page, as described in the install guide.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!-- To copy the form HTML, start here -->
<div class="quform-outer quform-theme-light-light">
    <form class="quform" action="quform/process-send-to-friend.php" method="post" enctype="multipart/form-data" onclick="">
 
        <div class="quform-inner">
            <h3 class="quform-title">Send this page to a friend</h3>
 
            <div class="quform-elements">
 
                <!-- Begin 2 column Group -->
                <div class="quform-group-wrap quform-group-style-plain quform-group-alignment-left">
                    <div class="quform-group-elements">
 
                        <div class="quform-group-row quform-group-row-3cols">
 
                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="name">Your Name <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="name" type="text" name="name" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->
 
                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="friends_name">Your Friend's Name <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="friends_name" type="text" name="friends_name" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->
 
                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="friends_email">Your Friend's Email <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="friends_email" type="text" name="friends_email" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->
 
                        </div>
 
                    </div>
                </div>
                <!-- End 3 column Group -->
 
                <!-- Begin Submit button -->
                <div class="quform-submit">
                    <div class="quform-submit-inner">
                        <button type="submit" value="Send"><span><em>Send</em></span></button>
                    </div>
                    <div class="quform-loading-wrap"><span class="quform-loading"></span></div>
                </div>
                <!-- End Submit button -->
           </div>
       </div>
    </form>
</div>
<!-- To copy the form HTML, end here -->
<!-- To copy the form HTML, start here -->
<div class="quform-outer quform-theme-light-light">
    <form class="quform" action="quform/process-send-to-friend.php" method="post" enctype="multipart/form-data" onclick="">

        <div class="quform-inner">
            <h3 class="quform-title">Send this page to a friend</h3>

            <div class="quform-elements">

                <!-- Begin 2 column Group -->
                <div class="quform-group-wrap quform-group-style-plain quform-group-alignment-left">
                    <div class="quform-group-elements">

                        <div class="quform-group-row quform-group-row-3cols">

                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="name">Your Name <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="name" type="text" name="name" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->

                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="friends_name">Your Friend's Name <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="friends_name" type="text" name="friends_name" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->

                            <!-- Begin Text input element -->
                            <div class="quform-element quform-element-text">
                                <div class="quform-spacer">
                                    <label for="friends_email">Your Friend's Email <span class="quform-required">*</span></label>
                                    <div class="quform-input">
                                        <input id="friends_email" type="text" name="friends_email" />
                                    </div>
                                </div>
                            </div>
                            <!-- End Text input element -->

                        </div>

                    </div>
                </div>
                <!-- End 3 column Group -->

                <!-- Begin Submit button -->
                <div class="quform-submit">
                    <div class="quform-submit-inner">
                        <button type="submit" value="Send"><span><em>Send</em></span></button>
                    </div>
                    <div class="quform-loading-wrap"><span class="quform-loading"></span></div>
                </div>
                <!-- End Submit button -->
           </div>
       </div>
    </form>
</div>
<!-- To copy the form HTML, end here -->

Step 2 – configure the process file

Make a copy of the quform/process.php file and call it process-send-to-friend.php and set these options:

1
$config['autoreply'] = true;
$config['autoreply'] = true;
1
$config['autoreplyRecipient'] = '%friends_email%';
$config['autoreplyRecipient'] = '%friends_email%';
1
$config['autoreplySubject'] = 'Your friend %name% thinks you might like this';
$config['autoreplySubject'] = 'Your friend %name% thinks you might like this';
1
$config['autoreplyBody'] = '/emails/send-to-friend.php';
$config['autoreplyBody'] = '/emails/send-to-friend.php';

At the form element configuration section, remove everything and add this code instead:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * Configure the name element
 * Filters: Trim
 * Validators: Required
 */
$name = new Quform_Element('name', 'Name');
$name->addFilter('trim');
$name->addValidator('required');
$form->addElement($name);
 
/**
 * Configure the friend's name element
 * Filters: Trim
 * Validators: Required
 */
$friendsName = new Quform_Element('friends_name', "Friend's name");
$friendsName->addFilter('trim');
$friendsName->addValidator('required');
$form->addElement($friendsName);
 
/**
 * Configure the friend's email element
 * Filters: Trim
 * Validators: Required, Email
 */
$friendsEmail = new Quform_Element('friends_email', "Friend's email");
$friendsEmail->addFilter('trim');
$friendsEmail->addValidators(array('required', 'email'));
$form->addElement($friendsEmail);
/**
 * Configure the name element
 * Filters: Trim
 * Validators: Required
 */
$name = new Quform_Element('name', 'Name');
$name->addFilter('trim');
$name->addValidator('required');
$form->addElement($name);

/**
 * Configure the friend's name element
 * Filters: Trim
 * Validators: Required
 */
$friendsName = new Quform_Element('friends_name', "Friend's name");
$friendsName->addFilter('trim');
$friendsName->addValidator('required');
$form->addElement($friendsName);

/**
 * Configure the friend's email element
 * Filters: Trim
 * Validators: Required, Email
 */
$friendsEmail = new Quform_Element('friends_email', "Friend's email");
$friendsEmail->addFilter('trim');
$friendsEmail->addValidators(array('required', 'email'));
$form->addElement($friendsEmail);

Step 3 – set the email content

Make a copy of the quform/emails/autoreply.php file and call it send-to-friend.php. Here is some example content to get you started:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php if (!defined('QUFORM_ROOT')) exit; ?><html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td valign="top" style="padding: 25px;"><table width="600" cellpadding="0" cellspacing="0" border="0" style="font: 14px Helvetica, Arial, sans-serif;">
            <tr>
                <td valign="top">Hi there <?php echo $form->getValueHtml('friends_name'); ?>!<br>
                <br>
                Your friend <?php echo $form->getValueHtml('name'); ?> thinks you might like a page on our site, check it out here:<br>
                <br>
                <a href="<?php echo Quform::escape(Quform::getReferer()); ?>">Click here to visit the page on our site</a><br>
                <br>
                We hope you will take a look!<br>
                <br>
                Kind Regards,<br>
                Company Name</td>
            </tr>
        </table></td>
    </tr>
</table>
</body>
</html>
<?php if (!defined('QUFORM_ROOT')) exit; ?><html>
<body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
        <td valign="top" style="padding: 25px;"><table width="600" cellpadding="0" cellspacing="0" border="0" style="font: 14px Helvetica, Arial, sans-serif;">
            <tr>
                <td valign="top">Hi there <?php echo $form->getValueHtml('friends_name'); ?>!<br>
                <br>
                Your friend <?php echo $form->getValueHtml('name'); ?> thinks you might like a page on our site, check it out here:<br>
                <br>
                <a href="<?php echo Quform::escape(Quform::getReferer()); ?>">Click here to visit the page on our site</a><br>
                <br>
                We hope you will take a look!<br>
                <br>
                Kind Regards,<br>
                Company Name</td>
            </tr>
        </table></td>
    </tr>
</table>
</body>
</html>
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy