Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Tech > [help]Problema allegati con Phpmailer
  Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
[help]Problema allegati con Phpmailer

Ho un problema ad aggiungere allegati con la classe Phpmailer, tramite un form contenuto in un sito.
la mail viene inviata correttamente ma al posto del file allegato che volevo inviare, c è un file temporaneo.
es : C:\PHP\uploadtemp\phpBD6.tmp
ovviamente non è sempre lo stesso, ogni volta che provo cambia il nome del file.

come posso risolvere questa cosa?
vi posto anche il codice

code:

<?php



if ($_REQUEST['Invia']) {





//aggiungo gli allegati


copy("$file","$file_name");




echo "allegato: ";
echo $file;
echo "<img src=\"".$file."\">";

include ("class.phpmailer.php");

//creazione istanza phpmailer
$mail = new phpmailer();

//seleziona il protocollo SMTP come modalità di spedizione
$mail->IsSMTP();

//nome dominio
$mail->Host = "smtp.miosito.it";

//segnala che è richiesta l autenticazione
$mail->SMTPAuth = TRUE;

//indicazione nome utente e password
$mail->Username = 'miamail@miosito.it';
$mail->Password = 'password';




//mittente
$mail->From = $_REQUEST['From'];
$mail->FromName = $_REQUEST['FromName'];
//$mail->From = "miamail@miosito.it";
//$mail->FromName = "preventivi stella";

//destinatario
//$mail->AddAddress($_REQUEST['TO'], $_REQUEST['ToName']);
$mail->AddAddress('miamail@miosito.it');





$mail->AddAttachment($file);


//oggetto e testo del messaggio
$mail->Subject = $_REQUEST['Subject'];
$mail->Body = $_REQUEST['Message'];

//formato testo o html
$mail->IsHTML = (boolean) $_REQUEST['FormatoHTML'];
if($mail->IsHTML) $mail->AltBody = strip_tags($_REQUEST['Message']);

if($mail->Send()) {
echo "<h2><p>Messaggio inviato con successo!</p></h2>";
} else {
echo "<p>Errore: ".$mail->ErrorInfo."</p>";
}

}

?>

<form method="post" enctype="multipart/form-data">
<table>
<tr>
<td>Nome del mittente: </td>
<td><input type="text" name="FromName" size="40" value="<?= htmlspecialchars($_REQUEST['FromName']) ?>"></td>
</tr>

<tr>
<td>Email del mittente: </td>
<td><input type="text" name="From" size="40" value="<?= htmlspecialchars($_REQUEST['From']) ?>"></td>
</tr>


<tr>
<td>Oggetto: </td>
<td><input type="text" name="Subject" size="40" value="<?= htmlspecialchars($_REQUEST['Subject']) ?>"></td>
</tr>

<tr>
<td>Messaggio: </td>
<td><textarea name="Message" rows="7" cols="40"><?= htmlspecialchars($_REQUEST['Message']) ?></textarea></td>
</tr>


<tr>
<td>Pima foto: </td>
<td><input type="file" name="file" size="40"></td>
</tr>


<tr>
<td></td>
<td><input type="submit" name="Invia" value="Invia messaggio"></td>
</tr>
</table>
</form>

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

Last edited by fulminato1 on 18-10-2005 at 20:10

18-10-2005 19:02
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

A vedere così, il problema sembra stare qui:

code:
//aggiungo gli allegati move_uploaded_file ($file, "$file_name") or die ("Impossibile uplodare il file sul server");

move_uploaded_file sposta un file già uploadato. Tu hai una sezione precedente che ti fa questo upload?

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

18-10-2005 19:52
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

scusa deep avevo sbagliato a copiare il codice esatto , ora ho corretto con:

code:
copy("$file","$file_name");

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

18-10-2005 20:11
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

però copy non ti uploada il file.
Prova a dare un'occhiata qui: http://it.php.net/manual/it/features.file-upload.php

Ma sei sicuro che la classe che stai usando non preveda già qualche funzione per l'upload dei file?

Purtroppo non mi sono mai occupato mail con allegati in php :alsono:

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

18-10-2005 20:20
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

copy sono sicuro che uploada il file perchè se poi vado a guardare tramite ftp la cartella sul server il file che volevo uploadare c è, lo usavo anche in un altro script per upload su server.

per quanto ne so io la classe phpmailer non ha nessuna funzione per l upload.
Gli allegati funzionano tranquillamente con file già presenti sul server nella stessa cartella dov è contenuto il mio script, ma il problema sta proprio nell'effettuare prima l upload del file nella cartella e poi allegarlo.
sembra che anche se l upload avviene prima del comando AddAttachment, il file non sia stao ancora uploadato completamente, ed infatti mi allega un file tmp.

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

18-10-2005 20:35
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by fulminato1
copy sono sicuro che uploada il file perchè se poi vado a guardare tramite ftp la cartella sul server il file che volevo uploadare c è, lo usavo anche in un altro script per upload su server..

Hai perfettamente ragione:

Originally posted by php.net
Come da PHP 4.3.0, sia source che dest potrebbero essere URL se "fopen wrappers" è stato abilitato.


Provato a cambiare

$mail->AddAttachment($file);

in

$mail->AddAttachment($file_name); ??

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

18-10-2005 20:58
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

già fatto e non cambia niente, sempre il solito problema.

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

19-10-2005 10:49
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

mi correggo, il file che arriva allegato alla mail è segnato come .jpg (quindi corretto), ma quando poi scarico l allegato non me lo apre come immagine, ma lo vede come un file strano senza estensione es: 11233546.
alla fine il .jpg è dato dal passaggio come parametro $file_name alla AddAttachment.
il nome è corretto ma il file non è leggibile.

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

19-10-2005 11:05
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

boh?

prova a postare la funzione AddAttachment()

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

19-10-2005 13:29
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

la funzione AddAttachment funziona perfettamente, l ho già provata con molti file già presenti sul server e aggiungendoli direttamente nel codice.
secondo me è tutta una questione di upload, lo script va avanti anche se effettivamente l upload non è stato terminato, oppure il file viene prima memorizzato in modo temporaneo prima della fine dello script e poi in modo definitivo.

ho fatto delle prove a mano e ho notato che file uploadati e che vengono tranquillamente visualizzati nelle pagine, se vado a cercarli tramite ftp appaiono solo dopo 4 o 5 refresh della cartella sul server.

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

19-10-2005 13:49
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.52 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

mah guarda, potresti inserire qualcosa di questo tipo

while (!file_exists($file)) {
echo "";
} else AddAttachment($file);


in questo modo, finché il file non è effettivamente su server, dovrebbe rimanere nel ciclo facendo degli echo fittizzi. Una volta che il file esiste sul server, allora esce e passa all'AddAttachment.

In teoria :D

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

19-10-2005 14:31
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
fulminato1
aLTeRaZioNeGuiTaRVoiCe

User info:
Registered: Oct 2003
Posts: 2809 (0.34 al dì)
Location: a casa.
Corso: comunicazio digital
Anno: secondo?
Time Online: 30 Days, 8:54:34 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

infatti in teoria, lavevo già provato e non funziona.

cmq ho risolto il tutto dividendo in varie pagine.
ho una prima pagina con il form per l invio dei dati che richiama un altra pagina che effettua l upload e ne da conferma.quest ultima infine porta a quella finale con i campi della mail da compilare.

ho usato un input tipe hidden per passare la variabile dalla prima all ultima e così funziona benone, anche se non mi garba molto a livello di programmazione. cercherò di migliorarlo però l importante è che funzioni.

grazie mille dell aiuto Deep, era da tempo che ci sbattevo la tesat contro!

__________________
www.alterazione.com www.andreaforzani.com
www.myspace.com/alterazione
www.myspace.com/festaincravilla

19-10-2005 15:30
Click Here to See the Profile for fulminato1 Click Here to See the Blog of fulminato1 Click here to Send fulminato1 a Private Message Visit fulminato1's homepage! Find more posts by fulminato1 Add fulminato1 to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 16:11.    Post New Thread    Post A Reply
  Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.132 seconds (59.25% PHP - 40.75% MySQL) con 25 query.