Bonjour à tous, j'ai repris un projet qui devrait voir la fin d'ici peu mais je rencontre un problème quant à la récupération d'une variable. En dehors de la fonction, la variable existe mais si je veux l'utiliser à l'intérieur de la fonction, elle me donne aucune valeur. Pouvez m'aider svp ?

Pour un peu dégrossir le sujet, je récupère la variable en question dans ma bdd et cette variable contient un email en fonction du logement. Et la fonction dans laquelle je dois utiliser la variable permet d'envoyer un mail. Voici un extrait de code (si vous voulez toute la page je peux vous la fournir)

La variable en question que je veux utiliser dans ma fonction se nomme $logement['email_logement']. Tout marche correctement lorsque $m_dest prend la valeur d'une valeur fixe mais c'est pas ce que je voudrais c'est pour cela que j'aimerais lui dire $m_dest = $logement['email_logement'];.

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
function envoyer_fiche () {
 
		$t_err = array(); 
		if ($_SERVER['HTTP_REFERER'] != "http"."://localhost/test.php") {
 
		{
				$t_err[] = "Anomalie localisation programme";
		} else {
			ini_set("SMTP","smtp.gandi.net");
			ini_set("smtp_port",25);
			$m_dest = //LA VARIABLE $logement['email_logement'] QUE J'AIMERAIS POUVOIR RECUPERER
			$separ = md5(uniqid(microtime(), true));
 
			// message
			$m_nom = htmlspecialchars($_POST['cnt_nom'], ENT_NOQUOTES, 'ISO-8859-15');
			$m_prenom = htmlspecialchars($_POST['cnt_prenom'], ENT_NOQUOTES, 'ISO-8859-15');
			$m_courriel = htmlspecialchars($_POST['cnt_courriel']);
			$m_objet = htmlspecialchars($_POST['cnt_objet'], ENT_NOQUOTES, 'ISO-8859-15');
			$m_message = htmlspecialchars($_POST['cnt_message'], ENT_NOQUOTES, 'ISO-8859-15');
 
			$headers = 'From: '.$m_courriel."\n";
			$headers .= "MIME-Version: 1.0"."\n";
 
 
			$m_mess = "";
 
			if ($_FILES['cnt_fichier']['tmp_name'] != "") {
				$headers .= 'Content-Type: multipart/mixed; boundary="'.$separ.'"'."\n";
				$m_mess .= "--".$separ."\n";
				$m_mess .= "Content-Type: text/plain; charset=\"iso-8859-15\""."\n";
				$m_mess .= "Content-Transfer-Encoding: 8bit"."\n\n";
			} else {
				$headers .= "Content-Type: text/plain; charset=\"iso-8859-15\""."\n";
				$headers .= "Content-Transfer-Encoding: 8bit"."\n";
			}
 
			$headers .= "\n";
 
			$m_mess .= "--------------------------------------------------------------------------------------"."\n";
			$m_mess .= "(issu de ".$_SERVER['HTTP_REFERER'].")"."\n\n";
			$dateh = date('d')."/".date('m')."/".date('Y'). " à ".date('H')."h".date('i');
			$m_mess .= "Ce message a été envoyé le ".$dateh."\n";
			$m_mess .= "--------------------------------------------------------------------------------------"."\n";
 
			$m_mess .= "Objet : ".$m_objet."\n\n";
 
			$m_mess .= "Nom : ".$m_nom."\n";
			$m_mess .= "Prénom : ".$m_prenom."\n\n";
 
			$m_mess .= "Message :"."\n\n";
			$m_mess .= $m_message."\n";
			$m_mess .= "--------------------------------------------------------------------------------------"."\n\n";
 
			// fichier joint
			$ok_fichier = "oui";
 
			if ($_FILES['cnt_fichier']['tmp_name'] != "") {
				$ok_fichier = fichier_joint ($m_mess, $t_err, $separ);
			}
 
			if ($ok_fichier == "oui") {
				$result = mail($m_dest, $m_objet, $m_mess, $headers);
				if (! $result) {
					$t_err[] = "Anomalie envoi messagerie";
				}
			}
		}
		return $t_err;
	}
Merci pour votre aide bon aprèm