execPieceByName('ff_InitLib'); // and the headerInfo library too $this->execPieceByName('ff_headerInfo'); // GLOBAL VARS global $form_field_category; global $form_field_email; global $form_field_message; global $fromname; global $date; // ADDITIONAL ADMIN RECIPIENTS BASED ON CATEGORY // ====================== EDIT FOLLOWING LINES =====================// $custom_categories = array( 'general enquiry' => 'cbrne@theitd.com', 'contact the editor' => 'cbrne@theitd.com', 'admin enquiry' => 'cbrne@theitd.com', 'advertising' => 'cbrne@theitd.com', 'exhibiting' => 'cbrne@theitd.com', 'problem with my account' => 'cbrne@theitd.com', 'something else' => 'cbrne@theitd.com' ); // STATIC VARS $form_field_email = 'email'; // field name for user's email $form_field_category = 'enquiry'; // field name to for the nature of the enquiry $form_field_message = 'message'; // field name for the body of the message // FORM VARIABLES (ALL) $form_fields_raw = $this->submitdata; $form_fields = array(); $i = 0; foreach ($form_fields_raw as $fields) { $form_fields[$i]['name'] = $fields[1]; $form_fields[$i]['label'] = $fields[2]; $form_fields[$i]['type'] = $fields[3]; $form_fields[$i]['value'] = $fields[4]; $i++; } // SITE CONFIG VARS $config = JFactory::getConfig(); $sitename = $config->get('sitename'); // i.e. 'Main Website' $mailfrom = $config->get('mailfrom'); // i.e. 'info@theitd.com' $fromname = $config->get('fromname'); // i.e. 'The ITD' // Creates a new JDate object equal to the current time $date = JFactory::getDate()->format('d/m/Y - H:i'); // Set the sender $sender = array( $mailfrom, $fromname ); // set default recipient to site admin and user to submitted email $admin_recipients = array($config->get('mailfrom')); $user_recipients = array(ff_getSubmit($form_field_email)); // check the subject and add the relevant email address to admin emails if (count($custom_categories) > 0) { foreach ($custom_categories as $key => $value) { if ($key == ff_getSubmit($form_field_category)) { array_push($admin_recipients, $value); } } } function emailSubject($s, $admin = true) { global $form_field_category; global $form_field_email; global $fromname; if ($admin) { $s->subject = "Message from the " . $fromname . " Website (" . ff_getSubmit($form_field_category) . ") [" . ff_getSubmit($form_field_email) . "]"; } else { $s->subject = "Your message through the " . $fromname . " Website"; } return $s; } // create the admin message object function emailMessage($m, $form_fields = array(), $admin = true) { global $date; global $fromname; global $form_field_message; $m->message = "

The following message was " . ($admin ? "received" : "sent") . " through the " . $fromname . " Website on " . $date . "

"; $m->message .= "

Message Details

"; $m->message .= ''; $m->message .= ''; $m->message .= ''; $m->message .= ''; $m->message .= '
'; $m->message .= ""; // loop through all fields foreach ($form_fields as $fields) { $m->message .= ""; $m->message .= ""; $m->message .= ""; } $m->message .= "
" . $fields['label'] . "" . $fields['value'] . "
"; $m->message .= '
'; $m->message .= "
"; // Admin message if ($admin) { // finally, tag on the header info (admin emails only) $m->message .= ff_headerInfo($m); } else { // User message $m->message .= "

We will be in touch as soon as possible.

"; } return $m; } // SEND EMAILS // ================================================== // function sendEmail($sender, $recipients, $subject, $body) { $mailer = JFactory::getMailer(); $mailer->setSender($sender); // make sure the recipient is in the correct format $mailer->addRecipient($recipients); $mailer->setSubject($subject); $mailer->isHtml(true); $mailer->Encoding = 'base64'; $mailer->setBody($body); $sendEmail = $mailer->Send(); return $sendEmail; } // admin email $admin_recipients = array_unique($admin_recipients); $admin_subject = emailSubject($this, true)->subject; $admin_body = emailMessage($this, $form_fields, true)->message; $sendAdmin = sendEmail($sender, $admin_recipients, $admin_subject, $admin_body); // user email $user_recipients = array_unique($user_recipients); $user_subject = emailSubject($this, false)->subject; $user_body = emailMessage($this, $form_fields, false)->message; $sendUser = sendEmail($sender, $user_recipients, $user_subject, $user_body); if (!$sendAdmin) { echo 'Failed sending Admin email'; } if (!$sendUser) { echo 'Failed sending User email'; }