Bonjour,

Je suis débutant en php et mon 1 er script perso tente de recupérer des informations dans une boite mail pour les envoyer vers SQL.



Bref j'en suis qu'au début et je test donc la fonction imap de php pour récupérer les informations nécéssaire. Connection ok j'arrive à récupérer les messages mais il y a un problème d'encodage car cela s'affiche comme cela :

=?ISO-8859-1?Q?Appartement_2_pi=E8ces_61,2m=B2?= Root User on Mon, 1 Sep 2014 14:55:09 +0200
=?ISO-8859-1?Q?2_PIECES_-_50m2_-_PARIS_15=E8me?= Root User on Mon, 1 Sep 2014 14:55:09 +0200
=?ISO-8859-1?Q?Appartement_Paris_19=E8me?= Root User on Mon, 1 Sep 2014 14:45:02 +0200
=?ISO-8859-1?Q?Appartement_2_pi=E8ces?= Root User on Mon, 1 Sep 2014 14:45:02 +0200
=?ISO-8859-1?Q?75003_-_4_pi=E8ces_-_70_m2_-_690_000_euros?= Root User on Mon, 1 Sep 2014 14:35:05 +0200
=?ISO-8859-1?Q?Beau_3_pi=E8ces_refait_=E0_neuf_-_rue_calme_75017?= Root User on Mon, 1 Sep 2014 14:35:05 +0200



Voici mon code pour l'instant :

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
 
<!DOCTYPE html>
<html>
  <head>
    <title>Mon script</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  <body>
    <p> Affichage de Gmail :</p>
 
<?php 
 
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'xxxxx@gmail.com';
$password = 'xxxxx';
 
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
 
/* grab emails */
$emails = imap_search($inbox,'ALL');
 
 
/* if emails are returned, cycle through each... */
if($emails) {
 
	/* begin output var */
	$output = '';
 
	/* put the newest emails on top */
	rsort($emails);
 
	/* for every email... */
	foreach($emails as $email_number) {
 
		/* get information specific to this email */
		$overview = imap_fetch_overview($inbox,$email_number,0);
		$message = imap_fetchbody($inbox,$email_number,2);
 
		/* output the email header information */
		$output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
		$output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
		$output.= '<span class="from">'.$overview[0]->from.'</span>';
		$output.= '<span class="date">on '.$overview[0]->date.'</span>';
		$output.= '</div>';
 
		/* output the email body */
		$output.= '<div class="body">'.$message.'</div>';
	}
 
	echo $output;
} 
 
/* close the connection */
imap_close($inbox);
?>
  </body>
</html>

Si vous savez comment je dois gérer ce problème d'affichage ?

D'autre part je voulais savoir ce que vous me conseillez d'utiliser comme fonctions pour aller extraire des informations dans les mails comme par exemple une date, un prix, un departement, un lien ?

Merci d'avance !