Bonjour,
j'ai réalisé un formulaire et je souhaiterai :
1. Que celui-ci, lorsqu'il est dument rempli et validé, me soit envoyé par e-mail (+ une copie à l'utilisateur à son adresse e-mail qu'il aura fourni dans le formulaire et dont je peux "adapter" la forme) ; cela est déjà dans le code, et ça ne fonctionne pas...Ainsi que, en en-tête (objet) du mail, je reçoive par exemple "Contact Website" et que dans le corps du message je reçoive, avec des retours chariot+br/, les informations qu'il aura précisé.
2. Que ça renvoie sur la page "process.php" comme souhaité (tout à l'heure ça marchait, et j'ai dû faire une connerie parce-que là ça marche plus, et je vois pas où est la boulette...).
Je vous fournis le formulaire "contact.html" :
Et la page de traitement de données "process.php" :
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > <head> <title>Contact</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <style type="text/css"> body { width: 100%; margin: auto; margin-top: 2%; margin-bottom: 2%; background-attachment:fixed; } h1 { padding-left: 30px; padding-right: 30px; color: white; text-align: center; text-decoration: underline; } fieldset { color: #00CCFF; border-color: #00CCFF; } #contact_direct p { font-color: black; margin-top: 0%; } #contact_via_website { font-color: black; } #corpus { margin-left: 10%; margin-right: 10%; margin-bottom: 3%; padding-top: 20px; padding-left: 20px; padding-right: 20px; padding-bottom: 20px; color: White; background-color: #626262; background-repeat: repeat-x; border: 2px solid black; } .font { font-family: "Trebuchet", Arial, Verdana, serif; font-size: 0.75em; color: black; } input, textarea, select { -moz-border-radius: 5px; -webkit-border-radius: 5px; -khtml-border-radius: 5px; border-radius: 5px; behavior: url("border-radius.htc"); border-color: #00CCFF; } .ui-button { margin-left: -1px; } .ui-button-icon-only { } .ui-button-text { padding: 0.35em; } .ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; } </style> </head> <body> <div id="corpus"> <div id="contact_via_website"> <form method="post" action="process.php"> <fieldset> <legend>Contact me via my website</legend> <p> <label for="civility" name="civility" class="font" tabindex="1">Civility</label><br /> <select name="civility" id="civility"> <option value=""></option> <option value="Mr.">Mr.</option> <option value="Ms.">Ms.</option> <option value="Mrs.">Mrs.</option> </select> </p> <p> <label for="last_name" name="last_name" class="font" tabindex="2">Last name</label><br /> <input type="text" name="last_name" /> <br /></p> <p> <label for="first_name" name="first_name" class="font" tabindex="3">First name</label><br /> <input type="text" name="first_name" /> <br /></p> <p> <label for="country" name="country" class="font">Country</label><br /> <select name="country"> <option selected>Select your country</option> <optgroup label="Africa"> <option value="Algeria">Algeria</option> <option value="Angola">Angola</option> <option value="Benin">Benin</option> <option value="Botswana">Botswana</option> <option value="Burkina Faso">Burkina Faso</option> <option value="Cameroon">Cameroon</option> <option value="Cape Verde">Cape Verde</option> <option value="Central African Republic">Central African Republic</option> <option value="Chad">Chad</option> <option value="Comoros">Comoros</option> <option value="Congo (Brazzaville)">Congo (Brazzaville)</option> <option value="Congo (Democratic Republic of the)">Congo (Democratic Republic of the)</option> <option value="Djibouti">Djibouti</option> <option value="Egypt">Egypt</option> <option value="Equatorial Guinea">Equatorial Guinea</option> <option value="Eritrea">Eritrea</option> <option value="Ethiopia">Ethiopia</option> <option value="Gabon">Gabon</option> <option value="Gambia">Gambia</option> <option value="Ghana">Ghana</option> <option value="Guinea">Guinea</option> <option value="Ivory Coast">Ivory Coast</option> <option value="Kenya">Kenya</option> <option value="Lesotho">Lesotho</option> <option value="Liberia">Liberia</option> <option value="Libyan Arab Jamahiriya">Libyan Arab Jamahiriya</option> <option value="Madagascar">Madagascar</option> <option value="Malawi">Malawi</option> <option value="Mali">Mali</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mayotte">Mayotte</option> <option value="Morroco">Morroco</option> <option value="Mozambique">Mozambique</option> <option value="Namibia">Namibia</option> <option value="Niger">Niger</option> <option value="Nigeria">Nigeria</option> <option value="Reunion">Reunion</option> <option value="Rwanda">Rwanda</option> <option value="Saint Helena">Saint Helena</option> <option value="Sao Tome and Principe">Sao Tome and Principe</option> <option value="Senegal">Senegal</option> <option value="Seychelles">Seychelles</option> <option value="Sierra Leone">Sierra Leone</option> <option value="Somalia">Somalia</option> <option value="South Africa">South Africa</option> <option value="Sudan">Sudan</option> <option value="Swaziland">Swaziland</option> <option value="Tanzania (United Republic of)">Tanzania (United Republic of)</option> <option value="Togo">Togo</option> <option value="Tunisia">Tunisia</option> <option value="Uganda">Uganda</option> <option value="Western Sahara">Western Sahara</option> <option value="Zambia">Zambia</option> </optgroup> <optgroup label="America"> <option value="Anguilla">Anguilla</option> <option value="Antigua and Barbuda">Antigua and Barbuda</option> <option value="Argentina">Argentina</option> <option value="Aruba">Aruba</option> <option value="Bahamas">Bahamas</option> <option value="Barbados">Barbados</option> <option value="Belize">Belize</option> <option value="Bermuda">Bermuda</option> <option value="Bolivia">Bolivia</option> <option value="Brazil">Brazil</option> <option value="British Virgin Islands">British Virgin Islands</option> <option value="Canada">Canada</option> <option value="Cayman Islands">Cayman Islands</option> <option value="Chile">Chile</option> <option value="Colombia">Colombia</option> <option value="Costa Rica">Costa Rica</option> <option value="Cuba">Cuba</option> <option value="Dominica">Dominica</option> <option value="Dominican Republic">Dominican Republic</option> <option value="Ecuador">Ecuador</option> <option value="Folkland Islands (Malvinas)">Folkland Islands (Malvinas)</option> <option value="French Guiana">French Guiana</option> <option value="Greenland">Greenland</option> <option value="Grenada">Grenada</option> <option value="Guadeloupe">Guadeloupe</option> <option value="Guatemala">Guatemala</option> <option value="Guyana">Guyana</option> <option value="Haiti">Haiti</option> <option value="Honduras">Honduras</option> <option value="Jamaica">Jamaica</option> <option value="Martinique">Martinique</option> <option value="Mexico">Mexico</option> <option value="Monserrat">Monserrat</option> <option value="Netherlands Antilles">Netherlands Antilles</option> <option value="Nicaragua">Nicaragua</option> <option value="Panama">Panama</option> <option value="Paraguay">Paraguay</option> <option value="Peru">Peru</option> <option value="Puerto Rico">Puerto Rico</option> <option value="Saint Kitts and Nevis">Saint Kitts and Nevis</option> <option value="Saint Lucia">Saint Lucia</option> <option value="Saint Pierre and Miquelon">Saint Pierre and Miquelon</option> <option value="Saint Vincent and the Grenadines">Saint Vincent and the Grenadines</option> <option value="Salvadore">Salvadore</option> <option value="Suriname">Suriname</option> <option value="Trinidad and Tobago">Trinidad and Tobago</option> <option value="Turks and Caicos Islands">Turks and Caicos Islands</option> <option value="United States of America">United States of America</option> <option value="Uruguay">Uruguay</option> <option value="Venezuela">Venezuela</option> <option value="Virgin Islands">Virgin Islands</option> </optgroup> <optgroup label="Asia Pacific"> <option value="Afghanistan">Afghanistan</option> <option value="Bangladesh">Bangladesh</option> <option value="Bhutan">Bhutan</option> <option value="Brunei">Brunei</option> <option value="Cambodia">Cambodia</option> <option value="China">China</option> <option value="Georgia">Georgia</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Japan">Japan</option> <option value="Kazakhstan">Kazakhstan</option> <option value="Kuwait">Kuwait</option> <option value="Kyrgyzstan">Kyrgyzstan</option> <option value="Laos">Laos</option> <option value="Malaysia">Malaysia</option> <option value="Maldives">Maldives</option> <option value="Mongolia">Mongolia</option> <option value="Myanmar">Myanmar</option> <option value="Nepal">Nepal</option> <option value="North Korea">North Korea</option> <option value="Pakistan">Pakistan</option> <option value="Papua New Guinea">Papua New Guinea</option> <option value="Philippines">Philippines</option> <option value="Singapore">Singapore</option> <option value="South Korea">South Korea</option> <option value="Sri Lanka">Sri Lanka</option> <option value="Taiwan">Taiwan</option> <option value="Tajikistan">Tajikistan</option> <option value="Thailand">Thailand</option> <option value="Turkmenistan">Turkmenistan</option> <option value="Uzbekistan">Uzbekistan</option> <option value="Vietnam">Vietnam</option> </optgroup> <optgroup label="Europe"> <option value="Albania">Albania</option> <option value="Andorra">Andorra</option> <option value="Austria">Austria</option> <option value="Belarus">Belarus</option> <option value="Belgium">Belgium</option> <option value="Bosnia-Herzegovina">Bosnia Herzegovina</option> <option value="Bulgaria">Bulgaria</option> <option value="Czech. Repuplic">Czech. Republic</option> <option value="Croatia">Croatia</option> <option value="Denmark">Denmark</option> <option value="Estonia">Estonia</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="Germany">Germany</option> <option value="Gibraltar">Gibraltar</option> <option value="Greece">Greece</option> <option value="Hungary">Hungary</option> <option value="Ireland">Ireland</option> <option value="Iceland">Iceland</option> <option value="Italy">Italy</option> <option value="Latvia">Latvia</option> <option value="Liechtenstein">Liechtenstein</option> <option value="Lithuania">Lithuania</option> <option value="Luxembourg">Luxembourg</option> <option value="Macedonia">Macedonia</option> <option value="Malta">Malta</option> <option value="Moldova">Moldova</option> <option value="Monaco">Monaco</option> <option value="Norway">Norway</option> <option value="Netherlands">Netherlands</option> <option value="Poland">Poland</option> <option value="Portugal">Portugal</option> <option value="Romania">Romania</option> <option value="Russian Federation">Russian Federation</option> <option value="San Marino">San Marino</option> <option value="Slovakia">Slovakia</option> <option value="Slovenia">Slovenia</option> <option value="Spain">Spain</option> <option value="Sweden">Sweden</option> <option value="Switzerland">Switzerland</option> <option value="Turkey">Turkey</option> <option value="United Kingdom">United Kingdom</option> <option value="Ukraine">Ukraine</option> <option value="Vatican">Vatican</option> <option value="Yugoslavia">Yugoslavia</option> </optgroup> <optgroup label="Middle East"> <option value="Bahrain">Bahrain</option> <option value="Iraq">Iraq</option> <option value="Iran">Iran</option> <option value="Israel">Israel</option> <option value="Jordania">Jordania</option> <option value="Kuwait">Kuwait</option> <option value="Lebanon">Lebanon</option> <option value="Oman">Oman</option> <option value="Palestine">Palestine</option> <option value="Qatar">Qatar</option> <option value="Saudi Arabia">Saudi Arabia</option> <option value="Syria">Syria</option> <option value="United Arab Emirates">United Arab Emirates</option> <option value="Yemen">Yemen</option> </optgroup> <optgroup label="Oceania"> <option value="Australia">Australia</option> <option value="Fiji">Fiji</option> <option value="French Polynesia">French Polynesia</option> <option value="Guam">Guam</option> <option value="Kiribati">Kiribati</option> <option value="Marshall Islands">Marshall Islands</option> <option value="Micronesia">Micronesia</option> <option value="New Caledonia">New Caledonia</option> <option value="New Zealand">New Zealand</option> <option value="Papua New Guinea">Papua New Guinea</option> <option value="Samoa">Samoa</option> <option value="Samoa (US)">Samoa (US)</option> <option value="Solomon (Islands)">Solomon (Islands)</option> <option value="Tonga">Tonga</option> <option value="Vanuatu">Vanuatu</option> </optgroup> </select> </p> <p> <label for="City" name="city" class="font" tabindex="4">City</label><br /> <input type="text" name="first name" /> <br /></p> <p> <label for="company" name="company" class="font" tabindex="5">Company</label><br /> <input type="text" name="Company" /> <br /></p> <p> <label for="e_mail" name="e_mail" class="font" tabindex="6">E-mail</label><br /> <input type="text" name="e_mail" /> <br /></p> <p> <label for="phone" name="phone_company" class="font" tabindex="7">Phone (company)</label><br /> <input type="text" name="phone_company" /> <br /></p> <p> <label for="phone" name="phone_cellular" class="font" tabindex="8">Phone (cellular)</label><br /> <input type="text" name="phone_cellular" /> <br /></p> <p> <label for="message" name="message" class="font" tabindex="9">Your message</label><br /> <textarea name="message" rows="20" cols="100"></textarea> </p> <p> <input type="submit" value="submit" name="submit" tabindex="10" /> </p> </fieldset> </form> </div> <form method="post"> <fieldset> <legend>Contact me directly</legend> <div id="contact_direct" class="font" name="contact_direct"><br /> <p><b><u>Postal adress :</u></b></p> <p>XXXXX XXXXX</p> <p>XXXXXXXXXXXXXXXXr</p> <p>XXXXX XXXXXXX</p><br /> <p><b><u>Phone number :</u></b></p> <p>XXXXXXXXXX</p><br /> <p><b><u>E-mail adress :</u></b></p> <p><u>contact@xxxxx.com</u></p><br /> </div> </fieldset> </form> </div> </body> </html>
Je crois que j'suis vraiment pas loin... mais... ça ne fonctionne pas...
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 <?php // destinataire est mon adresse mail. Pour envoyer à plusieurs à la fois, je peux séparer par des virgules $destinataire = 'XXXXX@gmail.com'; // il y a une redirec° de "contact@xxxx.com à celle là, normalement ca devrait marcher // copie ? (envoie une copie au visiteur) $copie = 'oui'; // notez que c est bien OUI ! // Action du formulaire (si ma page avait des paramètres dans l'URL) // si cette page etait index.php?page=contact alors j'aurai du mettre index.php?page=contact // sinon on laisse vide $form_action = ''; // Messages de confirmation du mail $message_envoye = "Your message has succesfully been sent to XXXXXX XXXXXX"; $message_non_envoye = "An error occurred. Please, try again."; // Message d'erreur du formulaire $message_formulaire_invalide = "An error occured. You forgot to specify one or several fields. Please, try again."; // cette fonction sert à nettoyer et enregistrer un texte function Rec($text) { $text = trim($text); // delete white spaces after & before text if (1 === get_magic_quotes_gpc()) { $stripslashes = create_function('$txt', 'return stripslashes($txt);'); } else { $stripslashes = create_function('$txt', 'return $txt;'); } // magic quotes ? $text = $stripslashes($text); $text = htmlspecialchars($text, ENT_QUOTES); // converts to string with " and ' as well $text = nl2br($text); return $text; }; /* * Cette fonction sert à vérifier la syntaxe d'un email */ function IsEmail($email) { $pattern = "^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,7}$"; return (eregi($pattern,$email)) ? true : false; }; $err_formulaire = false; // sert pour remplir le formulaire en cas d'erreur si besoin // si formulaire envoyé, on récupère tous les champs. Sinon, on initialise les variables. $civility = (isset($_POST['civility'])) ? Rec($_POST['civility']) : ''; $last_name = (isset($_POST['last_name'])) ? Rec($_POST['last_name']) : ''; $first_name = (isset($_POST['first_name'])) ? Rec($_POST['first_name']) : ''; $country = (isset($_POST['country'])) ? Rec($_POST['country']) : ''; $city = (isset($_POST['city'])) ? Rec($_POST['city']) : ''; $company = (isset($_POST['company'])) ? Rec($_POST['company']) : ''; $email = (isset($_POST['email'])) ? Rec($_POST['email']) : ''; $phone_company = (isset($_POST['phone_company'])) ? Rec($_POST['phone_company']) : ''; $phone_cellular = (isset($_POST['phone_cellular'])) ? Rec($_POST['phone_cellular']) : ''; $message = (isset($_POST['message'])) ? Rec($_POST['message']) : ''; if (isset($_POST['envoi'])) // je crois que c'est ici que j'ai chié dans la colle.......... { // On vérifie les variables et l'email ... $email = (IsEmail($email)) ? $email : ''; // soit l'email est vide si erroné, soit il vaut l'email entré $err_formulaire = (IsEmail($email)) ? false : true; if (($civility != '') && ($last_name != '') && ($first_name != '') && ($country != '') && ($city != '') && ($company != '') && ($email != '') && ($phone_company != '') && ($phone_cellular != '') && ($message != '')) { // les variables sont remplies, on génère puis envoie le mail $headers = 'From: '.$last_name .$first_name.' <'.$email.'>' . "\r\n"; // envoyer une copie au visiteur ? if ($copie == 'oui') { $cible = $destinataire.','.$email; } else { $cible = $destinataire; }; // Remplacement de certains caractères spéciaux $message = html_entity_decode($message); $message = str_replace(''',"'",$message); $message = str_replace('’',"'",$message); $message = str_replace('<br>','',$message); $message = str_replace('<br />','',$message); // Envoi du mail if (mail($cible, $civility, $last_name, $first_name, $country, $city, $company, $company, $e_mail, $phone_company, $phone_cellular, $message, $headers)) { echo '<p>'.$message_envoye.'</p>'."\n"; } else { echo '<p>'.$message_non_envoye.'</p>'."\n"; }; } else { // une des variables (ou plus) est vide ... echo '<p>'.$message_formulaire_invalide.' <a href="contact.html">Retour au formulaire</a></p>'."\n"; $err_formulaire = true; }; }; // fin du if (!isset($_POST['envoi'])) ?>![]()
Partager