Aller au contenu

Formulaire de devis et commande

[mfc_adv_form]
function mfc_adv_form_shortcode() { ob_start(); ?>

Type de demande








Prenez en photo votre devis/commande pour l'envoyer au service ADV de MFC ! (10 fichiers max, 5 Mo/fichier)

', 'Reply-To: ' . $email ); $attachments = array(); $max_files = 10; $max_size_per_file = 5 * 1024 * 1024; $allowed_mimes = array( 'image/png' => true, 'image/jpeg' => true, 'application/pdf' => true, ); if (!empty($_FILES['fichiers']) && isset($_FILES['fichiers']['name']) && is_array($_FILES['fichiers']['name'])) { require_once ABSPATH . 'wp-admin/includes/file.php'; $file_count = min(count($_FILES['fichiers']['name']), $max_files); for ($i = 0; $i < $file_count; $i++) { if (empty($_FILES['fichiers']['name'][$i])) continue; if ($_FILES['fichiers']['error'][$i] !== UPLOAD_ERR_OK) continue; $size = (int) $_FILES['fichiers']['size'][$i]; if ($size > $max_size_per_file) { wp_safe_redirect(add_query_arg('mfc_adv_status', 'toolarge', $redirect)); exit; } $single_file = array( 'name' => $_FILES['fichiers']['name'][$i], 'type' => $_FILES['fichiers']['type'][$i], 'tmp_name' => $_FILES['fichiers']['tmp_name'][$i], 'error' => $_FILES['fichiers']['error'][$i], 'size' => $size, ); $ft = wp_check_filetype_and_ext($single_file['tmp_name'], $single_file['name']); $mime = isset($ft['type']) ? $ft['type'] : ''; if (empty($mime) || !isset($allowed_mimes[$mime])) continue; $movefile = wp_handle_upload($single_file, array('test_form' => false)); if (!isset($movefile['error']) && !empty($movefile['file']) && file_exists($movefile['file'])) { $attachments[] = $movefile['file']; } } } $sent = wp_mail( array('accueil@mfc91.fr', 'info@mfc91.fr'), $subject, $body, $headers, $attachments ); if (!empty($attachments)) { foreach ($attachments as $path) { if (file_exists($path)) @unlink($path); } } wp_safe_redirect(add_query_arg('mfc_adv_status', $sent ? 'ok' : 'fail', $redirect)); exit; } add_shortcode('mfc_adv_form', 'mfc_adv_form_shortcode'); function mfc_adv_form_shortcode() { ob_start(); $status = isset($_GET['mfc_adv_status']) ? sanitize_text_field($_GET['mfc_adv_status']) : ''; ?>