Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 23
  1. #1

    Inviare via mail il risultato di una funzione

    Salve a tutti, come posso inviare via mail il risultato di una funzione? Posto il codice:

    codice:
    function showAnswers($answers,$questions) { 
    	for($x = 0; $x< count($answers); $x++) {
    		if ($x % 2 == 0) { 
    		 	$output = "<div class=\"qanda clear\">\n";
    		} else { 
    			$output = "<div class=\"qanda\">";
      		}
     	$output .= '<h4>Domanda' . ($x+1) . ': ' . $questions[$x] . '</h4>'; 
    	$output .= "
    1. \n"; for ($y = 0;$y< count($answers[$x]); $y++) { if (($answers[$x][$y] === $answers[$x][0]) && (in_array($answers[$x][$y],$_SESSION['correct']))) { $output .= "<li class=\"correctuser\">{$answers[$x][$y]} (Corretta!)\n"; } else if ($answers[$x][$y] === $answers[$x][0]) { $output .= "<li class=\"correct\">{$answers[$x][$y]}\n"; } else if (in_array($answers[$x][$y],$_SESSION['wrong'])) { $output .= "<li class=\"wrong\">{$answers[$x][$y]} (Erratta!)\n"; } else { $output .= "
    2. {$answers[$x][$y]}\n"; } } $output .= "
    </div>\n"; echo $output; } $to = "xxxx@email.com"; $subject = "Risultato quiz di $_SESSION[user]"; $message = "Nome: $_SESSION[user], "; $message .= "Cognome: $_SESSION[codverifica] "; $message .= "Risultati: $output"; $headers = "From: $_SESSION[email]". "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$message,$headers);
    Data la funzione sopra (che funziona alla perfezione) io vorrei inviare lo stesso risultato che mi manda a video via mail, ma se inserisco la variabile $output non visualizza nulla nella mail, se inserisco la funzione direttamente nella mail non invia nulla lo stesso resta tutto vuoto. Sono un paio di giorni che cerco la soluzione ma non riesco a trovare nulla. Qualcuno di voi sa come si potrebbe fare?

    Spero in un vostro aiuto.

    Grazie mille
    Federico

  2. #2
    Codice PHP:
    function showAnswers($answers,$questions) { 
        for(
    $x 0$xcount($answers); $x++) {
            if (
    $x == 0) { 
                 
    $output "<div class=\"qanda clear\">\n";
            } else { 
                
    $output "<div class=\"qanda\">";
              }
         
    $output .= '<h4>Domanda' . ($x+1) . ': ' $questions[$x] . '</h4>'
        
    $output .= "[list=1]\n";
         for (
    $y 0;$ycount($answers[$x]); $y++) {
             if ((
    $answers[$x][$y] === $answers[$x][0]) && (in_array($answers[$x][$y],$_SESSION['correct']))) {
                 
    $output .= "<li class=\"correctuser\">{$answers[$x][$y]} (Corretta!)\n";
             } else if (
    $answers[$x][$y] === $answers[$x][0]) {
                 
    $output .= "<li class=\"correct\">{$answers[$x][$y]}\n";
             } else if (
    in_array($answers[$x][$y],$_SESSION['wrong'])) {
                 
    $output .= "<li class=\"wrong\">{$answers[$x][$y]} (Erratta!)\n";
             } else { 
                 
    $output .= "[*]{$answers[$x][$y]}\n";
            }
        }
        
    $output .= "[/list]</div>\n";
        return 
    $output;
        }

    $to "xxxx@email.com";
    $subject "Risultato quiz di $_SESSION[user]";
    $message "Nome: $_SESSION[user],
     "
    ;
    $message .= "Cognome: $_SESSION[codverifica] 
    "
    ;
    $message .= "Risultati:  
    "
    .showAnswers();
    $headers "From: $_SESSION[email]""\r\n";
    $headers .= 'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    mail($to,$subject,$message,$headers); 
    Fammi sapere

  3. #3
    Grazie mille, ma l'avevo già provata e mi restituisce .showAnswers(array, array). Inoltre vorrei evitarla in quanto il tutto è su una pagina che vede a video l'utente, se la inserisco cosi mi vengono stampati a video i risultati cosa che devo evitare.

    Non riesco a venirne a capo, sicuramente è una fesseria ma non ci arrivo proprio!

  4. #4
    Scusa non avevo visto i parametri. Infatti la funzione necessita di 2 parametri

    $message .= "Risultati:
    ".showAnswers('parametro1','parametro2');

  5. #5
    Si l'avevo provata anche con i parametri, ripeto non mi restituisce nulla nella mail, inoltre non posso mettere quella in quanto mi restituisce a video i parametri cosa che devo evitare, non è possibile mettere la funzione in una variabile utilizzabile?

  6. #6
    Se vuoi mettere il risultato in una variabile devi sempre utilizzare il return nella funzione e aggiungere

    $risultato = echo(showAnswers('parametro1','parametro2'));
    $message .= "Risultati:
    ".$risultato;

    Prova così

  7. #7
    Questo viene segnalato come errore. Ho provato ad inserire la variabile in un file di testo ma il risultato è sempre vuoto, eppure a video lo vedo.

    $risultato = echo (showAnswers('answers','questions'));

  8. #8
    E se nella funzione aggiungi un terzo parametro "email" e includi l'invio del l'email nella funzione?

  9. #9
    Ci stavo pensando stanotte (quando si dice che la notte porta consiglio ) oggi provo ti faccio sapere.

    Grazie ancora per la disponibilità

  10. #10
    Mi sono perso, se inserisco un altro parametro e l'invio della mail all'interno della funzione non mi invia nulla, sicuramente ho sbagliato qualcosa.

    codice:
    function showAnswers2($answers,$questions,$sendemail) { 
    
    
    	for($x = 0; $x< count($answers); $x++) {
    		if ($x % 2 == 0) { 
    		 	$output = "<div class=\"qanda clear\">\n";
    		} else { 
    			$output = "<div class=\"qanda\">";
      		}
     	$output .= '<h4>Domanda' . ($x+1) . ': ' . $questions[$x] . '</h4>'; 
    	$output .= "
    1. \n"; for ($y = 0;$y< count($answers[$x]); $y++) { if (($answers[$x][$y] === $answers[$x][0]) && (in_array($answers[$x][$y],$_SESSION['correct']))) { $output .= "<li class=\"correctuser\">{$answers[$x][$y]} (Corretta!)\n"; } else if ($answers[$x][$y] === $answers[$x][0]) { $output .= "<li class=\"correct\">{$answers[$x][$y]}\n"; } else if (in_array($answers[$x][$y],$_SESSION['wrong'])) { $output .= "<li class=\"wrong\">{$answers[$x][$y]} (Erratta!)\n"; } else { $output .= "
    2. {$answers[$x][$y]}\n"; } } $output .= "
    </div>\n"; //echo $output; } //Invio email dei risultati $to = "xxx@xxx.it"; $subject = "Risultato quiz di $_SESSION[user]"; $message = "Nome: $_SESSION[user], "; $message .= "Codice Verifica: $_SESSION[codverifica] "; $message .= "Risultati: $sendemail "; $headers = "From: $_SESSION[email]". "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$message,$headers); }//Chiusura funzione
    Ho tolto l'eco per non stampare a video i risultati e fare tutto internamente senza che l'utente veda a video, ho provato a mettere la variabile $output ma essendo un ciclo mi inseriva nella mail solo l'ultimo risultato e non tutto. In che punto dovrei inserire la funzione per inserire nella mail tutto il ciclo?

    Grazie ancora per la disponibilità

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.