//--------------//
-function process() {
-
- $result['success'] = false;
-
- if($_SERVER['REQUEST_METHOD'] != 'POST') {
- $result['message'] = 'Invalid request';
- return $result;
- }
-
- // Check that important fields are present
- if(empty($_POST['_formID']) || empty($_POST['_recipient']) || empty($_POST['_verification'])) {
- $result['message'] = 'Error: missing form configuration data';
- return $result;
- }
-
- // Confirm that the form is valid and hasn't been tampered with
- $secret = SECRET_CODE; // see config.php
- $verification = md5("{$_POST['_recipient']}+{$_POST['_formID']}+$secret");
- if(strtolower($_POST['_verification']) != $verification) {
- $result['message'] = 'Error verifying form. E-mail could not be sent.';
- return $result;
- }
-
- // If we get to here, the form can be processed and the email sent.
- // First, build the email body
- $content = buildEmail($_POST);
-
- // Save data into a log file for this form
- $saved = saveData($content, $_POST['_formID']);
- if(!$saved) $result['save_error'] = true;
-
- // Send e-mail...
- require('PHPMailer/PHPMailerAutoload.php');
- $mail = new PHPMailer;
-
- $mail->From = 'no-reply@fluidbook.com';
- $mail->FromName = 'Fluidbook';
- $mail->addAddress($_POST['_recipient']);
- if (isset($_POST['email'])) { $mail->addReplyTo($_POST['email']); } // Guess the reply address field
- $mail->addBCC('test@cubedesigners.com');
-
- $mail->Subject = isset($_POST['_subject']) ? $_POST['_subject'] : 'Fluidbook e-mail form submission';
- $mail->Body = $content;
- //$mail->AltBody = $content;
-
- if(!$mail->send()) {
- $result['message'] = 'Error sending mail: '. $mail->ErrorInfo;
- } else {
- $result['message'] = 'Your information has been sent successfully';
- $result['success'] = true;
- }
-
- return $result;
+function process()
+{
+
+ $result['success'] = false;
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $result['message'] = 'Invalid request';
+ return $result;
+ }
+
+ // Check that important fields are present
+ if (empty($_POST['_formID']) || empty($_POST['_recipient']) || empty($_POST['_verification'])) {
+ $result['message'] = 'Error: missing form configuration data';
+ return $result;
+ }
+
+ // Confirm that the form is valid and hasn't been tampered with
+ $secret = SECRET_CODE; // see config.php
+ $verification = md5("{$_POST['_recipient']}+{$_POST['_formID']}+$secret");
+ if (strtolower($_POST['_verification']) != $verification) {
+ $result['message'] = 'Error verifying form. E-mail could not be sent.';
+ return $result;
+ }
+
+ // If we get to here, the form can be processed and the email sent.
+ // First, build the email body
+ $content = buildEmail($_POST);
+
+ // Save data into a log file for this form
+ $saved = saveData($content, $_POST['_formID']);
+ if (!$saved) $result['save_error'] = true;
+
+ // Send e-mail...
+ require('PHPMailer/PHPMailerAutoload.php');
+ $mail = new PHPMailer;
+ $mail->CharSet = 'UTF-8';
+
+ $mail->From = 'no-reply@fluidbook.com';
+ $mail->FromName = 'Fluidbook';
+ $mail->addAddress($_POST['_recipient']);
+ if (isset($_POST['email'])) {
+ $mail->addReplyTo($_POST['email']);
+ } // Guess the reply address field
+ $mail->addBCC('test@cubedesigners.com');
+
+ $mail->Subject = isset($_POST['_subject']) ? $_POST['_subject'] : 'Fluidbook e-mail form submission';
+ $mail->Body = $content;
+ //$mail->AltBody = $content;
+
+ if (!$mail->send()) {
+ $result['message'] = 'Error sending mail: ' . $mail->ErrorInfo;
+ } else {
+ $result['message'] = 'Your information has been sent successfully';
+ $result['success'] = true;
+ }
+
+ return $result;
}
// Save form data to a log file in the logs directory
-function saveData($data = null, $filename = null) {
+function saveData($data = null, $filename = null)
+{
- if(!$data || !filename) return false;
+ if (!$data || !filename) return false;
- $filename = preg_replace("/[^A-Za-z0-9]/", '', $filename); // Sanitize filename
- $filepath = "./logs/$filename.txt";
+ $filename = preg_replace("/[^A-Za-z0-9]/", '', $filename); // Sanitize filename
+ $filepath = "./logs/$filename.txt";
- $data .= "\n----\n\n"; // Small divider between entries
+ $data .= "\n----\n\n"; // Small divider between entries
- return file_put_contents($filepath, $data, FILE_APPEND | LOCK_EX);
+ return file_put_contents($filepath, $data, FILE_APPEND | LOCK_EX);
}
// Builds a string for use in the email based on array of data
// Array keys beginning with "_" are not included
-function buildEmail($data) {
+function buildEmail($data)
+{
- $res = 'Submission Date: '. date('Y-m-d H:i:s') . "\n\n";
+ $labels = [
+ 'date' => ['fr' => 'Date', 'en' => 'Date'],
+ 'surname' => ['fr' => 'Nom', 'en' => 'Surname'],
+ 'first_name' => ['fr' => 'Prénom', 'en' => 'First Name'],
+ 'phone' => ['fr' => 'Téléphone', 'en' => 'Phone'],
+ 'city' => ['fr' => 'Ville', 'en' => 'City'],
+ 'email' => ['fr' => 'E-mail', 'en' => 'Email'],
+ 'message' => ['fr' => 'Message', 'en' => 'Message'],
+ ];
- foreach($data as $key => $value) {
- if(substr($key, 0, 1) === '_') continue; // Ignore keys starting with "_"
+ $locale = $data['_locale'] ?? 'en';
- // Tidy up key names for presentation
- $key = ucwords(str_replace('_', ' ', $key));
- $res .= "$key: $value\n";
- }
+ $res = $labels['data']['locale'].': ' . date('Y-m-d H:i:s') . "\n\n";
- return $res;
+ foreach ($data as $key => $value) {
+ if (substr($key, 0, 1) === '_') continue; // Ignore keys starting with "_"
+
+ // Tidy up key names for presentation
+ $key = $labels[$key][$locale];
+ $res .= "$key: $value\n";
+ }
+
+ return $res;
}