J'ai 3 champs de type file dans mon formulaire, je voudrais recevoir les fichiers par mail, mais je bloque sur mon script,
Quelqu'un peut-til m'aider ?
mon champ de formulaire
Code : Tout sélectionner
<input type="file" name="fichier[]" id="fichier" multiple="multiple" class="inputfile inputfile-1" data-multiple-caption="{count} files selected"/>Code : Tout sélectionner
if ( $_POST && isset( $_FILES[ 'fichier' ] ) ) {
$destinataire = '[email protected]';
$recipient_email = "$destinataire";
$from_email = "$email";
$subject = "Objet";
$sender_name = "Mon nom";
$sender_email = "$email";
$sender_message = "contenu du message";
$attachments = $_FILES[ 'fichier' ];
$file_count = count( $attachments[ 'name' ] );
$boundary = md5( "domaine.fr" );
if ( $file_count > 0 ) {
$headers = "From: $email \n";
$headers .= "Reply-to: $sender_email \n";
$headers .= "X-Priority: 1 \n";
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\" \n";
$body = "--$boundary\r\n";
$body .= "Content-Type: text/html; charset=utf-8\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split( base64_encode( $sender_message ) );
for ( $x = 0; $x < $file_count; $x++ ) {
if ( !empty( $attachments[ 'name' ][ $x ] ) ) {
if ( $attachments[ 'error' ][ $x ] > 0 ) //exit script and output error if we encounter any
{
$mymsg = array(
1 => "Le poids de vos fichiers ne doit pas dépasser 2 mo",
2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form",
3 => "The uploaded file was only partially uploaded",
4 => "No file was uploaded",
6 => "Missing a temporary folder" );
die( $mymsg[ $attachments[ 'error' ][ $x ] ] );
}
$fileMax = 5242880;
$file_name = $attachments[ 'name' ][ $x ];
$file_size = $attachments[ 'size' ][ $x ];
$file_type = $attachments[ 'type' ][ $x ];
$maxfichier = 3;
$handle = fopen( $attachments[ 'tmp_name' ][ $x ], "r" );
$content = fread( $handle, $file_size );
fclose( $handle );
$encoded_content = chunk_split( base64_encode( $content ) ); //split into smaller chunks (RFC 2045)
$body .= "--$boundary\r\n";
$body .= "Content-Type: $file_type; name=\"$file_name\"\r\n";
$body .= "Content-Disposition: attachment; filename=\"$file_name\" \r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "X-Attachment-Id: " . rand( 1000, 99999 ) . "\r\n\r\n";
$body .= $encoded_content;
}
}
} else {
$headers = "From:" . $from_email . "\r\n" .
"Reply-To: " . $sender_email . "\n" .
"X-Mailer: PHP/" . phpversion();
$body = $sender_message;
}
$ok = 1;
if ( $pseudo == "" ) {
$ok = 0;
}
if ( $file_size > $fileMax ) {
$message = "<div class='w-100 bg-danger text-white text-center'>Le poids de vos fichiers ne doit pas dépasser 5 Mo <p class=\"float-center\"><A HREF=\"Javascript:history.go(-1)\">Modifier</A></div>";
$ok = 0;
}
if ( $file_count > 2 ) {
$message = "<div class='w-100 bg-danger text-white text-center'>Vous ne pouvez pas télécharger plus de 10 fichiers<p class=\"float-center\"><A HREF=\"Javascript:history.go(-1)\">Modifier</A></div>";
$ok = 0;
}
if ( $ok == 0 );
}
if ( $ok == 1 ) {
$display = 'style="display:none"';
$message = "<div class='w-100 bg-success text-white text-center'>Votre message a bien été envoyé</div>";
mail( $recipient_email, $subject, $body, $headers );
}