Bonsoir,

pour faire un mail avec pièce attachée, il faut commencer par uploader le fichier à attacher. Or dans mon code, l'upload ne se fait pas et je comprends pas pourquoi :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php 
$your_email ='---';// <<=== update to your email address
 
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$user_message = '';
 
if(isset($_POST['submit']))
{
 
	$name = $_POST['name'];
	$firstname = $_POST['firstname'];	
	$date = $_POST['date'];	
	$lieu = $_POST['lieu'];
	$marie = $_POST['marie'];
	$nbenf=$_POST['nbenf'];
 
	$chemin_destination = './';	
 
	if (isset($_FILES['file1']['name'])) {
	    move_uploaded_file($_FILES['file1']['tmp_name'],                    
                 $chemin_destination.$_FILES['file1']['name']);
	    $adr_file1=$chemin_destination.$_FILES['file1']['name'];
	}
 
	///------------Do Validations-------------
	if(empty($name)||empty($firstname)||empty($date)||empty($lieu))
	{
		$errors .= "Tous les champs sont obligatoires. ";	
	}
---		
	if(empty($errors))
	{
 
 
		//send the email
		$to = $your_email;
		$subject="test";
		$from = $your_email;
		$body = "A user  $name submitted the contact form:\n".
		"Name: $name\n".
		"Email: $visitor_email \n".
		"Message: \n ".
		"$user_message\n".
		$addbody=(isset($_FILES['file1']['name'])) ? "move_OK":"move_pas_OK";
		$body.=$addbody;
 
	$frontiere = '-----=' . md5(uniqid(mt_rand()));
 
	//-----------------------------------------------
	//HEADERS DU MAIL
	//-----------------------------------------------
 
	$headers = 'From: "'.$name." ".$firstname.'" <>'."\n";
	$headers.= 'Return-Path: <>'."\n";
	$headers.= 'MIME-Version: 1.0'."\n";
	$headers.= 'Content-Type: multipart/mixed; boundary="'.$frontiere."\"\n\n";
 
//-----------------------------------------------
	//MESSAGE
	//-----------------------------------------------
 
	$message ='This is a multi-part/mixed message in MIME format.'."\n";
	$message.='--'.$frontiere."\n";
	$message.='Content-Type: text/html; charset="ISO-8859-1"'."\n";
	$message.='Content-Transfer-Encoding: base64'."\n\n";
 
	$message.=chunk_split(base64_encode(nl2br($body)))."\n";
 
	//-----------------------------------------------
	//PIECE JOINTE
	//-----------------------------------------------
 
	if (isset($_FILES['file1']['name'])) {
	$base1=basename($adr_file1);
 
	$mime=$_FILES['file1']['type'];
 
	$message.='--'.$frontiere."\n";
	$message.= 'Content-Type: '.$mime.'; name='.$base1."\n";
	$message.= 'Content-Transfer-Encoding: base64'."\n";
	$message.= 'Content-Disposition:attachement; filename='.$base1."\n\n";
	$message.= chunk_split(base64_encode(file_get_contents($adr_file1)))."\n";
 
	}	
 
 
 
		mail($to, $subject, $message,$headers);
 
		header('Location: thank-you.html');
	}
}
 
?>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
<html>
<head>
  <meta content="text/html; charset=utf-8"
 http-equiv="content-type">
 
	<title>Contact Us</title>
<!-- define some style elements-->
<style>
label,a, body 
{
	font-family : Arial, Helvetica, sans-serif;
	font-size : 12px; 
}
.err
{
	font-family : Verdana, Helvetica, sans-serif;
	font-size : 12px;
	color: red;
}
</style>	
<!-- a helper script for vaidating the form-->
<script language="JavaScript" src="scripts/gen_validatorv31.js" type="text/javascript"></script>	
<!-- Datepicker -->
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css">
 
  <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
  <script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
 
  <script> $(function() { $( "#datepicker" ).datepicker(); }); </script>
</head>
 
<body>
<?php
if(!empty($errors)){
echo "<p class='err'>".nl2br($errors)."</p>";
}
?>
<div id='contact_form_errorloc' class='err'></div>
<form method="POST" name="contact_form" 
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> 
<p>
<label for='name'>Nom: </label><br>
<input type="text" name="name" value='<?php echo htmlentities($name) ?>'>
</p>
<p>
<label for='firstname'>Prénom: </label><br>
<input type="text" name="firstname" value='<?php echo htmlentities($firstname) ?>'>
</p>
<p>
<label for='date'>Né le: </label><br> <input id="datepicker" type="text" name="date" value='<?php echo htmlentities($date)?>'>
 
</p>
<p>
<label for='lieu'>Lieu: </label><br>
<input type="text" name="lieu" value='<?php echo htmlentities($lieu) ?>'>
</p>
<p>
<label for='marie'>Marié:</label> <br>
<input type="checkbox" name="marie" value='<?php echo htmlentities($marie) ?>'>
</p>
<p>
<label for='nbenf'>Nombre d'enfants : </label><br>
<input type="text" name="nbenf" value='<?php echo htmlentities($nbenf) ?>'>
</p>
<p>Fichier attaché : <input name="MAX_FILE_SIZE"
 value="3100000" type="hidden"><br> <input name="file1"
 type="file"><br></p>
<p>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>" id='captchaimg' ><br>
<label for='message'>Entrez le code ici :</label><br>
<input id="6_letters_code" name="6_letters_code" type="text"><br>
<small>Vous ne pouvez lire l'image? cliquez <a href='javascript: refreshCaptcha();'>ici</a> pour rafraichir</small>
</p>
<input type="submit" value="Envoyer" name='submit'>
</form>
<script language="JavaScript">
// Code for validating the form
// Visit http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
// for details
var frmvalidator  = new Validator("contact_form");
//remove the following two lines if you like error message box popups
frmvalidator.EnableOnPageErrorDisplaySingleBox();
frmvalidator.EnableMsgsTogether();
 
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("email","req","Please provide your email"); 
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
</script>
<script language='JavaScript' type='text/javascript'>
function refreshCaptcha()
{
	var img = document.images['captchaimg'];
	img.src = img.src.substring(0,img.src.lastIndexOf("?"))+"?rand="+Math.random()*1000;
}
</script>
</body>
</html>