Adding Confirmation Emails Forms
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Feb 2015 16:07:52 +0000 (11:07 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 27 Feb 2015 16:07:52 +0000 (11:07 -0500)
Adding to Giveaway and Getaway form.
using templates:
giveawayConfEmail.tpl
getawayConfEmail.tpl

Toolkit/Contacts/ContactUs.php
Toolkit/Contacts/GolfGiveaway.php
Toolkit/Contacts/GreatBigGaylordGolfGetaway.php
Toolkit/Contacts/templates/emailOwner.tpl
Toolkit/Contacts/templates/getawayConfEmail.tpl [new file with mode: 0755]
Toolkit/Contacts/templates/giveawayConfEmail.tpl [new file with mode: 0755]

index 4336cdc..04fd2a3 100755 (executable)
@@ -873,6 +873,61 @@ class Toolkit_Contacts_ContactUs
         }
     }
 
+/**
+     * Emails the owner the submitted data from the submitted form
+     *
+     * Uses a flexy template to render a nice looking html email.
+     * Fills in the supplied data from the form and doesn't add the
+     * empty fields the user didn't fill in.
+     *
+     * @param string $mailFactory What type of mail factory should we use
+     *
+     * @return boolean result of the mailing
+     * @access protected
+     */
+    protected function sendConfirmation(
+        $emailSubject,
+        $emailTemplate,
+        $mailFactory = 'mail'
+    ) {
+
+        $template = new HTML_Template_Flexy($this->flexyOptions);
+        $page     = new stdClass();
+        // for comments textarea need to replace newlines with br
+        $this->formData['comments']['element']
+            = nl2br($this->getSubmitValue('comments'));
+
+        $userEmail = $this->getSubmitValue('email');
+        $page->email_from  = OWNER_EMAIL;
+        $page->subject     = $emailSubject;
+        $page->fname       = $this->getSubmitValue('fname');
+        $page->lname       = $this->getSubmitValue('lname');
+
+        $template->compile($emailTemplate);
+        $htmlMsg = $template->bufferedOutputObject($page);
+
+        $msg  = "{$page->subject}\n\n";
+        $msg .= "From {$page->fname} {$page->lname}\n\n";
+
+        $mimeMail = new Mail_mime("\n");
+        $mimeMail->setFrom("Gaylord Golf Mecca <".OWNER_EMAIL.">");
+        $mimeMail->setSubject($emailSubject);
+        $mimeMail->setHTMLBody($htmlMsg);
+        $mimeMail->setTXTBody($msg);
+
+        $mail =& Mail::factory($mailFactory);
+        $body = $mimeMail->get();
+        $headers = $mimeMail->headers($setHeader);
+
+        $res = $mail->send($this->email, $headers, $body);
+        if (PEAR::isError($res)) {
+            return Toolkit_Common::handleError($res);
+        } else {
+            return $res;
+        }
+    }
+
+
     /**
      * Display errors with the form to the user
      *
@@ -1103,6 +1158,9 @@ class Toolkit_Contacts_ContactUs
             if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) {
                 $this->freeze();
                 $this->emailOwner();
+                if (method_exists($this, 'confirmation')) {
+                    $this->confirmation();
+                }
                 $output = $this->successMsg;
             }
             $this->sent = true;
index 693e710..a08254e 100755 (executable)
@@ -470,4 +470,19 @@ class Toolkit_Contacts_GolfGiveaway
     }
 
     //    }}}
+    /**
+     * confirmation
+     *
+     * Send out the Confirmation email with subject and using template
+     *
+     * @access public
+     * @return void
+     */
+    public function confirmation()
+    {
+        $this->sendConfirmation(
+            'Gaylord Golf Giveaway', // Email Subject
+            'giveawayConfEmail.tpl' // Email Template File
+        );
+    }
 }
index ef7235e..c5d1084 100755 (executable)
@@ -339,5 +339,21 @@ class Toolkit_Contacts_GreatBigGaylordGolfGetaway
         $this->setupElements($e);
     }
 
+
+    /**
+     * confirmation
+     *
+     * Send out the Confirmation email with subject and using template
+     *
+     * @access public
+     * @return void
+     */
+    public function confirmation()
+    {
+        $this->sendConfirmation(
+            'Confirmation: Gaylord. America’s Summer Golf Mecca', // Email Subject
+            'getawayConfEmail.tpl' // Email Template File
+        );
+    }
     //    }}}
 }
index e574342..470ae94 100755 (executable)
@@ -1,61 +1,61 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
-       <meta http-equiv="content-type" content="text/html;charset=utf-8">
-       <title>{title:h}</title>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title>{title:h}</title>
 </head>
 <body>
-       <!-- {{{ body -->
-       <p>
-               <font size="4" face="arial, sans-serif">
-                       <b>{subject:h}</b>
-               </font>
-       </p>
-       <p>
-               <font size="3" face="arial, sans-serif">
-                       <b>From {fname:h} {lname:h}</b>
-               </font>
-       </p>
-       <table cellspacing="0" cellpadding="0" bgcolor="#c0c0c0" border="0">
-               <tr>
-                       <td>
-                               <table cellspacing="1" cellpadding="5" border="0" bgcolor="#c0c0c0" width="400">
-                                       {foreach:formData,v}
-                                               <tr flexy:if="v[element]" bgcolor="#c0c0c0">
-                                                       <td align="right" bgcolor="#ffffff">
-                                                               <font size="2" face="arial, sans-serif">
-                                                                       <b>{v[label]:h}</b>
-                                                               </font>
-                                                       </td>
-                                                       {if:v[nowrap]}
-                                                               <td nowrap bgcolor="#ffffff">
-                                                                       <font size="2" face="arial, sans-serif">{v[element]:h}</font>
-                                                               </td>
-                                                       {else:}
-                                                               <td bgcolor="#ffffff">
-                                                                       <font size="2" face="arial, sans-serif">{v[element]:h}</font>
-                                                               </td>
-                                                       {end:}
-                                               </tr>
-                                       {end:}
-                               </table>
-                       </td>
-               </tr>
-               <tr>
-                       <td>
-                               <table cellspacing="0" cellpadding="10" border="0" width="400">
-                                       <tr>
-                                               <td bgcolor="#eeeeee">
-                                                       <font size="1" face="arial, sans-serif">
-                                                               To ensure the delivery of these e-mails to your inbox, please add {email_from:h} to your e-mail Address Book or Safe List.
-                                                       </font>
-                                               </td>
-                                       </tr>
-                               </table>
-                       </td>
-               </tr>                           
-                                                       
-       </table>
-       <!-- }}} -->
+    <!-- {{{ body -->
+    <p>
+        <font size="4" face="arial, sans-serif">
+            <b>{subject:h}</b>
+        </font>
+    </p>
+    <p>
+        <font size="3" face="arial, sans-serif">
+            <b>From {fname:h} {lname:h}</b>
+        </font>
+    </p>
+    <table cellspacing="0" cellpadding="0" bgcolor="#c0c0c0" border="0">
+        <tr>
+            <td>
+                <table cellspacing="1" cellpadding="5" border="0" bgcolor="#c0c0c0" width="400">
+                    {foreach:formData,v}
+                        <tr flexy:if="v[element]" bgcolor="#c0c0c0">
+                            <td align="right" bgcolor="#ffffff">
+                                <font size="2" face="arial, sans-serif">
+                                    <b>{v[label]:h}</b>
+                                </font>
+                            </td>
+                            {if:v[nowrap]}
+                                <td nowrap bgcolor="#ffffff">
+                                    <font size="2" face="arial, sans-serif">{v[element]:h}</font>
+                                </td>
+                            {else:}
+                                <td bgcolor="#ffffff">
+                                    <font size="2" face="arial, sans-serif">{v[element]:h}</font>
+                                </td>
+                            {end:}
+                        </tr>
+                    {end:}
+                </table>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <table cellspacing="0" cellpadding="10" border="0" width="400">
+                    <tr>
+                        <td bgcolor="#eeeeee">
+                            <font size="1" face="arial, sans-serif">
+                                To ensure the delivery of these e-mails to your inbox, please add {email_from:h} to your e-mail Address Book or Safe List.
+                            </font>
+                        </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>               
+                            
+    </table>
+    <!-- }}} -->
 </body>
 </html>
diff --git a/Toolkit/Contacts/templates/getawayConfEmail.tpl b/Toolkit/Contacts/templates/getawayConfEmail.tpl
new file mode 100755 (executable)
index 0000000..cb70da9
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title>{title:h}</title>
+</head>
+<body>
+    <!-- {{{ body -->
+    <p>
+        <font size="4" face="arial, sans-serif">
+            <b>{subject:h}</b>
+        </font>
+    </p>
+    <table cellspacing="0" cellpadding="0" bgcolor="#c0c0c0" border="0">
+        <tr>
+            <td>
+               <p>Thank you for entering the Gaylord America's Summer Golf Mecca's \"Great Big Gaylord Golf Getaway!</p>
+               <p>If you would like additional information on Golf in the Gaylord Area please visit
+               <a href="http://www.gaylordgolfmecca.com">www.gaylordgolfmecca.com</a></p>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <table cellspacing="0" cellpadding="10" border="0" width="400">
+                    <tr>
+                        <td bgcolor="#eeeeee">
+                            <font size="1" face="arial, sans-serif">
+                                To ensure the delivery of these e-mails to your inbox,
+                                please add {email_from:h} to your e-mail Address Book or Safe List.
+                            </font>
+                        </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+    </table>
+    <!-- }}} -->
+</body>
+</html>
diff --git a/Toolkit/Contacts/templates/giveawayConfEmail.tpl b/Toolkit/Contacts/templates/giveawayConfEmail.tpl
new file mode 100755 (executable)
index 0000000..a69999b
--- /dev/null
@@ -0,0 +1,38 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+    <meta http-equiv="content-type" content="text/html;charset=utf-8">
+    <title>{title:h}</title>
+</head>
+<body>
+    <!-- {{{ body -->
+    <p>
+        <font size="4" face="arial, sans-serif">
+            <b>{subject:h}</b>
+        </font>
+    </p>
+    <table cellspacing="0" cellpadding="0" bgcolor="#c0c0c0" border="0">
+        <tr>
+            <td>
+               <p>Thank you for entering to win a FREE 4 Nights/4 Days (6 rounds) GOLF PACKAGE to the Gaylord Golf Mecca!</p>
+               <p>This is a confirmation of your entry in the Gaylord Golf Giveaway</p>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                <table cellspacing="0" cellpadding="10" border="0" width="400">
+                    <tr>
+                        <td bgcolor="#eeeeee">
+                            <font size="1" face="arial, sans-serif">
+                                To ensure the delivery of these e-mails to your inbox,
+                                please add {email_from:h} to your e-mail Address Book or Safe List.
+                            </font>
+                        </td>
+                    </tr>
+                </table>
+            </td>
+        </tr>
+    </table>
+    <!-- }}} -->
+</body>
+</html>