Advertisement
theitd

End Submit Piece - BreezingForms

Dec 16th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.30 KB | None | 0 0
  1. <?php // remember to remove
  2.  
  3. // include FacileForms standard library
  4. $this->execPieceByName('ff_InitLib');
  5.  
  6. // and the headerInfo library too
  7. $this->execPieceByName('ff_headerInfo');
  8.  
  9. // GLOBAL VARS
  10. global $form_field_category;
  11. global $form_field_email;
  12. global $form_field_message;
  13. global $fromname;
  14. global $date;
  15.  
  16. // ADDITIONAL ADMIN RECIPIENTS BASED ON CATEGORY
  17. // ======================  EDIT FOLLOWING LINES =====================//
  18. $custom_categories = array(
  19.     'general enquiry' => 'cbrne@theitd.com',
  20.     'contact the editor' => 'cbrne@theitd.com',
  21.     'admin enquiry' => 'cbrne@theitd.com',
  22.     'advertising' => 'cbrne@theitd.com',
  23.     'exhibiting' => 'cbrne@theitd.com',
  24.     'problem with my account' => 'cbrne@theitd.com',
  25.     'something else' => 'cbrne@theitd.com'
  26. );
  27.  
  28. // STATIC VARS
  29. $form_field_email = 'email';      // field name for user's email
  30. $form_field_category = 'enquiry';    // field name to for the nature of the enquiry
  31. $form_field_message = 'message';    // field name for the body of the message
  32.  
  33. // FORM VARIABLES (ALL)
  34. $form_fields_raw = $this->submitdata;
  35. $form_fields = array();
  36. $i = 0;
  37. foreach ($form_fields_raw as $fields) {
  38.     $form_fields[$i]['name'] = $fields[1];
  39.     $form_fields[$i]['label'] = $fields[2];
  40.     $form_fields[$i]['type'] = $fields[3];
  41.     $form_fields[$i]['value'] = $fields[4];
  42.     $i++;
  43. }
  44.  
  45. // SITE CONFIG VARS
  46. $config = JFactory::getConfig();
  47. $sitename = $config->get('sitename'); // i.e.  'Main Website'
  48. $mailfrom = $config->get('mailfrom'); // i.e. 'info@theitd.com'
  49. $fromname = $config->get('fromname'); // i.e. 'The ITD'
  50.  
  51. // Creates a new JDate object equal to the current time
  52. $date = JFactory::getDate()->format('d/m/Y - H:i');
  53.  
  54. // Set the sender
  55. $sender = array(
  56.     $mailfrom,
  57.     $fromname
  58. );
  59.  
  60. // set default recipient to site admin and user to submitted email
  61. $admin_recipients = array($config->get('mailfrom'));
  62. $user_recipients = array(ff_getSubmit($form_field_email));
  63.  
  64. // check the subject and add the relevant email address to admin emails
  65. if (count($custom_categories) > 0) {
  66.     foreach ($custom_categories as $key => $value) {
  67.         if ($key == ff_getSubmit($form_field_category)) {
  68.             array_push($admin_recipients, $value);
  69.         }
  70.     }
  71. }
  72.  
  73. function emailSubject($s, $admin = true)
  74. {
  75.     global $form_field_category;
  76.     global $form_field_email;
  77.     global $fromname;
  78.  
  79.     if ($admin) {
  80.         $s->subject = "Message from the " . $fromname . " Website (" . ff_getSubmit($form_field_category) . ") [" . ff_getSubmit($form_field_email) . "]";
  81.     } else {
  82.         $s->subject = "Your message through the " . $fromname . " Website";
  83.     }
  84.  
  85.     return $s;
  86. }
  87.  
  88. // create the admin message object
  89. function emailMessage($m, $form_fields = array(), $admin = true)
  90. {
  91.  
  92.     global $date;
  93.     global $fromname;
  94.     global $form_field_message;
  95.  
  96.     $m->message = "<p>The following message was " . ($admin ? "received" : "sent") . " through the " . $fromname . " Website on <b>" . $date . "</b></p>";
  97.     $m->message .= "<h3 style=\"text-decoration:underline; text-transform: uppercase; font-weight: 100\">Message Details</h3>";
  98.     $m->message .= '<table border="0" cellpadding="0" cellspacing="0" height="100%" width="100%">';
  99.     $m->message  .= '<tr>';
  100.     $m->message  .= '<td align="left" valign="top">';
  101.  
  102.         $m->message .= "<table border=\"0\" cellpadding=\"5\" cellspacing=\"0\" width=\"600\">";
  103.         // loop through all fields
  104.         foreach ($form_fields as $fields) {
  105.             $m->message .= "<tr>";
  106.             $m->message .= "<td nowrap><code>" . $fields['label'] . "</code></td><td><code><b>" . $fields['value'] . "</b></code></td>";
  107.             $m->message .= "</tr>";
  108.         }
  109.  
  110.         $m->message .= "</table>";
  111.         $m->message .= '</td>';
  112.         $m->message .= '</tr>';
  113.         $m->message .= '</table>';
  114.         $m->message .= "<hr>";
  115.  
  116.     // Admin message
  117.     if ($admin) {
  118.         // finally, tag on the header info (admin emails only)
  119.         $m->message .= ff_headerInfo($m);
  120.     } else {
  121.         // User message
  122.         $m->message .= "<p>We will be in touch as soon as possible.</p>";
  123.     }
  124.  
  125.     return $m;
  126.  
  127. }
  128.  
  129. // SEND EMAILS
  130. // ================================================== //
  131.  
  132. function sendEmail($sender, $recipients, $subject, $body)
  133. {
  134.     $mailer = JFactory::getMailer();
  135.  
  136.     $mailer->setSender($sender);
  137.  
  138.     // make sure the recipient is in the correct format
  139.     $mailer->addRecipient($recipients);
  140.  
  141.     $mailer->setSubject($subject);
  142.     $mailer->isHtml(true);
  143.     $mailer->Encoding = 'base64';
  144.     $mailer->setBody($body);
  145.  
  146.     $sendEmail = $mailer->Send();
  147.  
  148.     return $sendEmail;
  149. }
  150.  
  151. // admin email
  152. $admin_recipients = array_unique($admin_recipients);
  153. $admin_subject = emailSubject($this, true)->subject;
  154. $admin_body = emailMessage($this, $form_fields, true)->message;
  155.  
  156. $sendAdmin = sendEmail($sender, $admin_recipients, $admin_subject, $admin_body);
  157.  
  158. // user email
  159. $user_recipients = array_unique($user_recipients);
  160. $user_subject = emailSubject($this, false)->subject;
  161. $user_body = emailMessage($this, $form_fields, false)->message;
  162.  
  163. $sendUser = sendEmail($sender, $user_recipients, $user_subject, $user_body);
  164.  
  165. if (!$sendAdmin) {
  166.     echo 'Failed sending Admin email';
  167. }
  168. if (!$sendUser) {
  169.     echo 'Failed sending User email';
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement