Bonjour à tous.

Voila, je suis en train de mettre en place un formulaire de contact et il a l'air de fonctionner très bien.
Cependant, lorsque je l'ai testé avec d'autres adresses mails (chez wanadoo, orange, free....), tous les caractères accentués sont remplacés par des i que ça soit dans le sujet du mail ou dans son contenu. Voici la classe en question:

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
401
402
403
404
405
406
407
408
409
410
<?php
 
class simplemail {
 
	var $recipientlist;
	var $subject;
	var $hfrom;
	var $hbcc;
	var $hcc;
 
	var $Xsender;
	var $ErrorsTo;
	var $XMailer = 'PHP';
	var $XPriority = 3;
 
	var $set_mode='php';
 
	var $text;
	var $html;
	var $attachement;
	var $htmlattachement;
 
	var $recipient;	
 
	var $body;
	var $headers;
	var $error_log;
        var $connect;
 
	var $default_charset = 'iso-8859-1';
 
	var $B1B = "----=_001";
	var $B2B = "----=_002";
	var $B3B = "----=_003";
 
 
	function simplemail() {
		$this -> attachement = array();
		$this -> htmlattachement = array();
	}
 
	function checkaddress($address) {
		if ( preg_match('`([[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4}))`', $address) ) {
			return TRUE;
		} else {
			$this->error_log("l'adresse $address est invalide"); return FALSE;
		}
	}
 
	function checkname($name) {
		if ( preg_match("`[0-9a-zA-Z\.\-_ ]*`" , $name ) ) {
			return TRUE;
		} else {
			$this->error_log(" le pseudo $name est invalide\n"); return FALSE;
		}
	}
 
	function makenameplusaddress($address,$name) {
		if ( !$this->checkaddress($address) ) return FALSE;
		if ( !$this->checkname($name) ) return FALSE;
		if ( empty($name) ) { return $address; }
		else { $tmp=$name." <".$address.">"; return $tmp; }
	}
 
	function addrecipient($newrecipient,$name='') {
		$tmp=$this->makenameplusaddress($newrecipient,$name);
		if ( !$tmp ) { $this->error_log(" To: error"); return FALSE; }
		$this->recipientlist[] = array( 'mail'=>$newrecipient, 'nameplusmail' => $tmp );
		return TRUE;
	}
 
	function addbcc($bcc,$name='') {
		$tmp=$this->makenameplusaddress($bcc,$name);
		if ( !$tmp ) { $this->error_log(" Bcc: error"); return FALSE; }
		if ( !empty($this->hbcc)) $this->hbcc.= ",";
		$this->hbcc.= $tmp;
		return TRUE;
	}
 
	function addcc($cc,$name='') {
		$tmp=$this->makenameplusaddress($cc,$name);
		if ( !$tmp ) { $this->error_log(" Cc: error\n"); return FALSE; }
		if (!empty($this->hcc)) $this->hcc.= ",";
		$this->hcc.= $tmp;
		return TRUE;
	}
 
	function addsubject($subject) {
		if (!empty($subject)) $this->subject = $subject;
	}
 
	function addfrom($from,$name='') {
		$tmp=$this->makenameplusaddress($from,$name);
		if ( !$tmp ) { $this->error_log(" From: error"); return FALSE; }
		$this->hfrom = $tmp;
		return TRUE;
	}
 
	function addreturnpath($return) {
		$tmp=$this->makenameplusaddress($return,'');
		if ( !$tmp ) { $this->error_log("Return-Path: error"); return FALSE; }
		$this->returnpath = $return;
		return TRUE;
	}
 
	function addreplyto($replyto) {
		$tmp=$this->makenameplusaddress($replyto,'');
		if ( !$tmp ) { $this->error_log(" Reply-To: error"); return FALSE; }
		$this->returnpath = $tmp;
		return TRUE;
	}
 
 
	// les attachements
	function addattachement($filename) {
		array_push ( $this -> attachement , array ( 'filename'=> $filename ) );
	}
 
	// les attachements html
	function addhtmlattachement($filename,$cid='',$contenttype='') {
		array_push ( $this -> htmlattachement ,
                  array ( 'filename'=>$filename ,
                    'cid'=>$cid ,
                    'contenttype'=>$contenttype )
		);
	}
 
	function writeattachement(&$attachement,$B) {
		$message = '';
		if ( !empty($attachement) ) {
			foreach($attachement as $AttmFile){
				$patharray = explode ("/", $AttmFile['filename']);
				$FileName = $patharray[count($patharray)-1];
 
				$message .= "\n--".$B."\n";
 
				if (!empty($AttmFile['cid'])) {
					$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
					$message .= "Content-Transfer-Encoding: base64\n";
					$message .= "Content-ID: <{$AttmFile['cid']}>\n";
					$message .= "Content-Disposition: inline;\n filename=\"".$FileName."\"\n\n";
				} else {
					$message .= "Content-Type: application/octetstream;\n name=\"".$FileName."\"\n";
					$message .= "Content-Transfer-Encoding: base64\n";
					$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
				}
 
				$fd=fopen ($AttmFile['filename'], "rb");
				$FileContent=fread($fd,filesize($AttmFile['filename']));
				fclose ($fd);
 
				$FileContent = chunk_split(base64_encode($FileContent));
				$message .= $FileContent;
				$message .= "\n\n";
			}
			$message .= "\n--".$B."--\n";
		}
		return $message;
	}
 
	function BodyLineWrap($Value) {
		return wordwrap($Value, 78, "\n ");
	}
 
	function makebody() {
		$message='';
		if ( !$this->html && $this->text && !empty($this->attachement) ) {
 
			//Messages start with text/html alternatives in OB
			$message ="This is a multi-part message in MIME format.\n";
			$message.="\n--".$this->B1B."\n";
 
			$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
			$message.="Content-Transfer-Encoding: quoted-printable\n\n";
			// plaintext goes here
			$message.=$this->BodyLineWrap($this->text)."\n\n";
 
			$message.=$this->writeattachement($this->attachement,$this->B1B);
 
		}
		elseif ( !$this->html && $this->text && empty($this->attachement) ) {
 
			// plaintext goes here
			$message.=$this->BodyLineWrap($this->text)."\n\n";
		}
		elseif ( $this->html ) {
 
			//Messages start with text/html alternatives in OB
			$message ="This is a multi-part message in MIME format.\n";
			$message.="\n--".$this->B1B."\n";
 
			$message.="Content-Type: multipart/related;\n\t boundary=\"".$this->B2B."\"\n\n";
			//plaintext section
			$message.="\n--".$this->B2B."\n";
 
			$message.="Content-Type: multipart/alternative;\n\t boundary=\"".$this->B3B."\"\n\n";
			//plaintext section
			$message.="\n--".$this->B3B."\n";
 
			$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
			$message.="Content-Transfer-Encoding: quoted-printable\n\n";
			// plaintext goes here
			$message.=$this->BodyLineWrap($this->text)."\n\n";
 
			// html section
			$message.="\n--".$this->B3B."\n";
			$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
			$message.="Content-Transfer-Encoding: base64\n\n";
			// html goes here
			$message.=chunk_split(base64_encode($this->html))."\n\n";
 
			// end of text
			$message.="\n--".$this->B3B."--\n";
 
			// attachments html
			if (empty($this->htmlattachement)) {
				$message.="\n--".$this->B2B."--\n";
			} else {
				$message.=$this->writeattachement( $this->htmlattachement,$this->B2B);
			}
 
			// attachments
			if (empty($this->attachement)) {
				$message.="\n--".$this->B1B."--\n";
			} else {
				$message.=$this->writeattachement($this->attachement,$this->B1B);
			}
 
		}
 
		$this->body = $message;
 
		return $message;
 
	}
 
	// Mail Headers Methods
 
	function MakeHeaderField($Field,$Value) {
        return wordwrap($Field.": ".$Value, 78, "\n ")."\r\n";
	}
 
	function AddField2Header($Field,$Value) {
		$this->headers .= $this->MakeHeaderField($Field,$Value);
	}
 
	function makeheader() {
 
		$this->headers = '';
 
		if ( empty($this->recipientlist) ) { $this->error_log("destinataire manquant"); return FALSE; }
//		else { $this->AddField2Header("To",$this->recipient); }
 
		if ( empty($this->subject) ) {
			$this->error_log("sujet manquant");
			return FALSE; 
		} else {
			if ($this->set_mode!='php' ) {
				$this->AddField2Header("Subject", $this->subject);
			}
		}
 
 
		# Date: Mon, 03 Nov 2003 20:48:06 +0100
		$this->AddField2Header("Date", date ('r'));
 
		if ( !empty($this->Xsender) ) { $this->AddField2Header("X-Sender",$this->Xsender); }
		else { $this->AddField2Header("X-Sender",$this->hfrom); }
 
		if ( !empty($this->ErrorsTo) ) { $this->AddField2Header("Errors-To",$this->ErrorsTo); }
		else { $this->AddField2Header("Errors-To",$this->hfrom); }
 
		if ( !empty($this->XMailer) ) $this->AddField2Header("X-Mailer",$this->XMailer);
 
		if ( !empty($this->XPriority) ) $this->AddField2Header("X-Priority",$this->XPriority);
 
		if ( !empty($this->hfrom) ) $this->AddField2Header("From",$this->hfrom);
 
		if ( !empty($this->returnpath) ) $this->AddField2Header("Return-Path",$this->returnpath);
 
		if ( !empty($this->replyto) ) $this->AddField2Header("Reply-To",$this->replyto);
 
		$this->headers .="MIME-Version: 1.0\r\n";
 
		if ( !$this->html && $this->text && !empty($this->attachement) ) {		
			$this->headers .= "Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
		} elseif ( !$this->html && $this->text && empty($this->attachement) ) {	
			$this->headers .="Content-Type: text/plain; charset=us-ascii; format=flowed\r\n";
			$this->headers .="Content-Transfer-Encoding: 7bit\r\n";
		} elseif ( $this->html ) {			
			if ( !$this->text ) { $this->text="HTML only!"; }
			$this->headers .="Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
		}
 
		if ( !empty($this->hcc) ) $this->AddField2Header("Cc",$this->hcc);
		if ( !empty($this->hbcc) ) $this->AddField2Header("Bcc",$this->hbcc);
 
		return $this->headers;
	}
 
	function sendmail() {
		$this->makebody();
		$this->makeheader();
		switch($this->set_mode)	{
			case 'php' : $this->phpmail(); break;
			case 'socket': $this->socketmailloop(); break;
		}
                return TRUE;
	}
 
	// Mail send by PHPmail
 
	function phpmail() {
		while ( list($key, $to) = each($this->recipientlist) ) {
			$this->recipient = $to['mail'];
			if ( mail($to['mail'], $this->subject, $this->body, $this->makeheader() ) ) { 
				$this->error_log("envoie vers {$to['nameplusmail']} r�ussi");
			} else { 
				$this->error_log("envoie vers {$to['nameplusmail']} echou�");
			}
		}
		return TRUE; 
	}
 
	// Socket Function
 
	function SocketStart() {
		if (!$this->connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30))  { 
            $this->error_log("Could not talk to the sendmail server!"); return FALSE; 
        };
	    return fgets($this->connect, 1024);
	}
 
	function SocketStop() {
	  	fclose($this->connect);
		return TRUE;
	}
 
	function SocketSend($in,$wait='') {
		fputs($this->connect, $in, strlen($in));
		echo "-"; flush();
		if(empty($wait)) {
			$rcv = fgets($this->connect, 1024);
			return $rcv;
		}
		return TRUE;
	}
 
	// Mail Socket	
 
	function socketmailstart() {
 
		$this->SocketStart();     		
		if (!isset($_SERVER['SERVER_NAME'])  || empty($_SERVER['SERVER_NAME'])) { $serv = 'unknown'; }
		else { $serv = $_SERVER['SERVER_NAME']; }
		$this->SocketSend("HELO $serv\r\n");
        }
 
	function socketmailsend($to) {
 
		$this->recipient = $to;
		$this->error_log("Socket vers $to");
 
		$this->SocketSend( "MAIL FROM:{$this->hfrom}\r\n" );
		$this->SocketSend( "RCPT TO:$to\r\n" );
		$this->SocketSend( "DATA\r\n" );	
		$this->SocketSend( $this->CleanMailDataString($this->headers)."\r\n", 'NOWAIT' );	
		$this->SocketSend( $this->CleanMailDataString($this->body)."\r\n", 'NOWAIT' );	
		$this->SocketSend( ".\r\n" );
		$this->SocketSend( "RSET\r\n" );
 
		$this->error_log("Fin de l'envoi vers $to");
 
		return TRUE;        
    }
 
    function socketmailstop() {      
		$this->SocketSend("QUIT\r\n");
	  	$this->SocketStop();
		return TRUE;
	}
 
    function socketmailloop() {
        $this->socketmailstart();
        while ( list($key, $to) = each($this->recipientlist)) {
			$this->recipient = $to['mail'];
			$this->makeheader();
            $this->socketmailsend($to['mail']);
		}
        $this->socketmailstop();
    }
 
	// Misc.
 
	function error_log($msg='') {
		if(!empty($msg)) { 
				$this->error_log .= $msg . "\r\n--\r\n";
				return TRUE; 
		}
		return " --- Error Log --- \r\n\r\n".$this->error_log;
	}
 
	function CleanMailDataString($data) {
		$data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data);
        $data = preg_replace("/\n\n/", "\n\r\n", $data);
        $data = preg_replace("/\n\./", "\n..", $data);
		return $data;
	}
}
?>
et mon code que j'utilise
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$adressemail = new simplemail;
//ajout du destinataire
$adressemail -> addrecipient($mailservice , $lignes->Intitule_service);
// ajout de l'expediteur
$adressemail -> addfrom('nepasrepondre','Formulaire de contact du site  ... .fr');
$adressemail -> addsubject($lignes->Intitule_service.': Message laissé par le biais du formulaire de contact du site ... .fr');
$today = date("d-m-Y à H:i:s");
$messageaenvoye="";
$messageaenvoye.="Un message a été laissé par le biais du site internet ... .fr.\n\n L'identité de ce correspondant est:  $nom  $prenom .\n Il cherche à joindre le service: $lignes->Intitule_service .\n\nPour répondre à ce mail, utilisez cette adresse $mail. Il s'agit de l'adresse mail de votre correspondant. \n\n Voici le message qui a été laissé: \n\n\n\n $message.\n\n\n\n\n\n Il est préférable de ne pas jetter ce mail afin de garder trace du message.\n\n Ce message a été laissé à la date du: $today";
$messagesecurite=$ip;
$adressemail -> text = utf8_decode($messageaenvoye)."\n\n\n\n".utf8_decode($messagesecurite)."\n\n\n\n".utf8_decode("Ce message est envoyé automatiquement, veuillez ne pas y répondre.");
?>
Sur ma boite mail, le mail s'affiche très très bien, par contre sur les autres, il y a un problème d'encodage de caractère.
Quelqu'un voit-il mon problème?

lemirandais