$details_sheet->setCellValueByColumnAndRow(0, $current_row, $user_detail['label'] . ' :');
$details_sheet->setCellValueByColumnAndRow(1, $current_row, $user_detail['value']);
+ $details_sheet->getRowDimension($current_row)->setRowHeight(-1); // Auto row height from content
$current_row++;
}
$details_sheet->getColumnDimensionByColumn(1)->setAutoSize(true);
//==== Save the Excel spreadsheet to disk temporarily
- // $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); // The .xlsx extension seems to prevent the e-mail from delivering...
- $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5'); // Older .xls format is fine for our needs
+ $writer = PHPExcel_IOFactory::createWriter($excel, 'Excel2007'); // .xlsx format
$xls_file = CubeIT_Files::tempnam();
$writer->save($xls_file);
$user_details['email']['value'],
];
$return_address = 'postmaster@fluidbook.com';
- $email_from = "CFOC <$return_address>";
- $email_reply_to = 'CFOC <pro@cfoc.com>';
+ $email_from_name = "CFOC";
+ $email_reply_to = 'pro@cfoc.com';
$email_subject = $_POST['email_subject'] ?? 'Récapitulatif de votre commande CFOC';
$email_body = "Bonjour,\n\nVotre commande est en cours de traitement (récapitulatif en pièce jointe). Nous vous recontacterons dans les meilleurs délais.\n\nCordialement,\n\nL'équipe CFOC";
// Send the email
- $mail = new cubeMail();
- $mail->returnPath = $return_address;
- $mail->charset = 'UTF-8';
- $mail->to = implode(',', $email_to);
- $mail->cc = implode(',', $email_cc);
- $mail->from = $email_from;
- $mail->replyTo = $email_reply_to;
- $mail->subject = $email_subject;
- $mail->body = $email_body;
-
- // Attach the generated spreadsheet file
- // I found when using the .xlsx extension, the mail isn't delivered. Interestingly, it's not the actual format
- // that causes the problem because a .xlsx file named as .xls would be delivered. It must be a mail server
- // configuration but the older version of Excel is fine for our needs, so that's what is used for the format.
- $mail->addFile('CFOC-' . date('YmdHis') . '.xls', $xls_file);
- $result['success'] = $mail->send();
+ $transport = new CubeIT_Mail_Transport_Mailjet();
+ $mail = new CubeIT_Mail_Mailjet();
+ $mail->setFrom($return_address, $email_from_name);
+ $mail->setReplyTo($email_reply_to, $email_from_name);
+ $mail->setReturnPath($return_address);
+ foreach ($email_to as $to_recipient) {
+ $mail->addTo($to_recipient);
+ }
+ foreach ($email_cc as $cc_recipient) {
+ $mail->addCc($cc_recipient);
+ }
+ $mail->setSubject($email_subject);
+ $mail->setBodyText($email_body);
+
+ $attachment_filename = 'CFOC-' . date('YmdHis') . '.xlsx';
+
+ $mail->createAttachment(
+ file_get_contents($xls_file),
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
+ Zend_Mime::DISPOSITION_ATTACHMENT,
+ Zend_Mime::ENCODING_BASE64,
+ $attachment_filename
+ );
+
+ try {
+ print_r($mail->send($transport));
+ $result['success'] = true;
+ } catch (Exception $e){
+ error_log('#### CFOC: Failed sending message via Mailjet ####');
+ error_log('ERROR: ' . $e->getMessage());
+ $result['success'] = false;
+ }
unlink($xls_file); // Tidy up temporary file after sending
if (file_exists($referencesFile) || CubeIT_Util_Url::isDistant($referencesFile)) {
$raw_data = wsUtil::excelToArray($referencesFile);
- $first_sheet_rows = reset($raw_data); // First sheet's data will be returned since it's the first array element
+ $first_sheet_rows = reset($raw_data); // First row's data will be returned since it's the first array element
// Expected headings are: EXCLU, LIGNE, EAN, REF, DESIGNATION, COULEUR, QTE MINI, PRIX TTC
$column_headings = array_shift($first_sheet_rows); // We assume the first row will be the headings, so we slice it off
// For the 'EXCLU' field, this should be converted to a boolean
$row['EXCLU'] = ('exclu boutique' === $row['EXCLU']);
+ // Make sure the PRIX TTC field doesn't have any stray commas or spaces in the numbers
+ // because this will cause unexpected problems for the calculations
+ $row['PRIX TTC'] = str_replace([',', ' '], '', $row['PRIX TTC']);
+
// The EAN and REF are required, so if they don't exist, we can assume it's not a valid row
if (empty($row['EAN']) || empty($row['REF'])) {
continue;