Bonjour,
merci de prendre 2 min pour lire ceci !

je suis sur un script pour récupérer les fichiers joints dans 1 ou des mails...
Je précise que la connexion se passe bien, qu'il compte correctement le nombre de mail(s) ainsi que le nombre de pièces jointes mais AUSSI et c'est le pire (le mieux) les fichiers sont enregistrer au bon endroit et ne sont pas corrompus !, voici le script :

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
 
<?php
 $boiteMail = 'pop3.x.fr';
  $port = 110;
  $login = 'photo@x.fr';
  $motDePasse = 'xXx';
 
  $mail = imap_open('{'.$boiteMail.':'.$port.'/pop3}', $login, $motDePasse);
 
$nbmess = imap_num_msg($mail);
if ($nbmess == 0){
	echo "
		<div align='center'>
		 <b>Aucun message présent sur le serveur</b>
	<br /><br />
		</div>
	";
}else{
	for($j=1;$j<=$nbmess;$j++)
{
 
$header = imap_headerinfo($mail,$j);
$sujet = $header->subject;
$struct = imap_fetchstructure($mail,$j);
if ($struct->type == 1){
	$nbrparts = !$struct->parts ? "1" : count($struct->parts);
}
$piece = array();
for($h=1;$h<=$nbrparts;$h++){
	$part = $struct->parts[1] ;
	$piece = imap_fetchbody($mail,$j,$h+1);
 
	if ($part->encoding == "3"){
		$nbparam = count($part->parameters);
		$i=0;
		while ($i < $nbparam){
			$i++;
			$nom_fichier = $struct->parts[$h]->parameters[0]->value;
 
		}
		$piece = imap_base64($piece);
	}
	$newfichier = ""; 
	$newfichier = fopen("pj/".$nom_fichier,"w+" );
	fwrite($newfichier,$piece);
	fclose($newfichier);
}
}}
?>
les erreurs (reprises 1 fois par mail lu) :

Notice: Undefined offset: 6 in C:\monChemin\mail2.php on line 43

Notice: Trying to get property of non-object in C:\monChemin\mail2.php on line 43

Notice: Trying to get property of non-object in C:\monChemin\mail2.php on line 43

Warning: fopen(pj/): failed to open stream: No such file or directory in C:\monChemin\mail2.php on line 51

Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\monChemin\mail2.php on line 53

Warning: fclose() expects parameter 1 to be resource, boolean given in C:\monChemin\mail2.php on line 55

La ligne 43 :
$nom_fichier = $struct->parts[$h]->parameters[0]->value;
La ligne 53 :
fwrite($newfichier,$piece);
La ligne 55 :
fclose($newfichier);
d'avance merci beaucoup !
Zeb