syntax error

  • Creatore Discussione Creatore Discussione nora61
  • Data di inizio Data di inizio

nora61

Nuovo Utente
19 Dic 2008
8
0
0
www.noracosa.ch
Ciao a tutti,
sono novellina sia qui nel forum che con PHP... ho copiato ed adattato uno script che ho trovato qui sul forum per il formmail. pur troppo mi da sempre il seguente errore: syntax error, unexpected T_ELSE in d:\www\www93\formmail.php on line 65

qualcuno mi può aiutare a venirne a capo su quello che sbaglio?

grazie mille in anticipo

nora

il mio codice:

<?php // Recupero il valore dei campi del form$empfaenger = $_POST[' empfaenger'];
$stickunterlage = $_POST[' stickunterlage '];
$groesse = $_POST[' groesse '];
$anzahlfarben = $_POST[' anzahlfarben '];
$anzahlteile = $_POST[' anzahlteile '];
$mitteilung = $_POST[' mitteilung '];
$nachvorname = $_POST[' nachvorname '];
$adresse = $_POST[' adresse '];
$ortplz = $_POST[' ortplz '];
$telefon= $_POST[' telefon '];
$email = $_POST[' email '];
$anhang= $_POST[' anhang '];
$senden = $_POST[' senden '];
$loeschen = $_POST[' loeschen '];
// Valorizzo le variabili relative all'allegato
$anhang = $_FILES['anhang']['tmp_name'];
$anhang_type = $_FILES['anhang']['type'];
$anhang_name = $_FILES['anhang']['name'];
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($anhang));
{
// Apro e leggo il file allegato
$file = fopen($anhang,'rb');
$data = fread($file, filesize($anhang));
fclose($file);

// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));

// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $mitteilung . "\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$anhang_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";

// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";
}
else
{
$msg = $messaggio;
}

// Invio la mail
if (mail($destinatario, $oggetto, $msg, $headers))
{
echo "<p>Mail inviata con successo!</p>";
}else{
echo "<p>Errore!</p>";
}
?>
 
Ciao e grazie per la risposta....
ho già fatto come da te consigliato ma non funziona lo stesso.

PHP:
<?php 
// Recupero il valore dei campi del form
$empfaenger = $_POST[' empfaenger'];
$stickunterlage = $_POST[' stickunterlage '];
$groesse = $_POST[' groesse '];
$anzahlfarben = $_POST[' anzahlfarben '];
$anzahlteile = $_POST[' anzahlteile '];
$mitteilung = $_POST[' mitteilung '];
$nachvorname = $_POST[' nachvorname '];
$adresse = $_POST[' adresse '];
$ortplz = $_POST[' ortplz '];
$telefon= $_POST[' telefon '];
$email = $_POST[' email '];
$anhang= $_POST[' anhang '];
$senden = $_POST[' senden '];
$loeschen = $_POST[' loeschen '];
$betreff = $_POST[' betreff '];

// Valorizzo le variabili relative all'allegato
$anhang = $_FILES['anhang']['tmp_name'];
$anhang_type = $_FILES['anhang']['type'];
$anhang_name = $_FILES['anhang']['name'];


// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($anhang))
{
// Apro e leggo il file allegato
$file = fopen($anhang,'rb');
$data = fread($file, filesize($anhang));
fclose($file);

// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));

// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $mitteilung . "\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$anhang_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";

// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";
}
else
{
$msg = $mitteilung;
}

// Invio la mail
if (mail($empfaenger, $betreff, $msg, $headers))
{
echo "<p>Ihre E-Mail wurde erfogreich gesendet. Vielen Dank für Ihre Anfrage!</p>";
}else{
echo "<p>Fehler!</p>";
}
?>


ed il codice html:

HTML:
<form action="formmail.php" method="post"
 enctype="multipart/form-data">
<input name="empfaenger" value="anfragen@miodominio.ch" type="hidden">
<table border="0" cellpadding="2" cellspacing="5"><tbody><tr><td>
Vorlage:<br>
Formate:</td><td>
<input name="anhang" type="file"><br>
TlF, JPG,&nbsp;GIF,&nbsp;BMP, PNG, PDF, PSD </td>
</tr><tr><td>
Stickunterlage:<br><br>
Grösse in mm:</td><td>
<select name="stickunterlage">
<option>..................................</option>
<option>Jeans</option>
<option>T-Shirt</option>
<option>Pullover</option>
<option>Frottewäsche</option>
<option>Leintücher</option>
<option>Autositzbezüge</option>
<option value="">Andere</option>
</select><br><br>
<input size="5" name="groesse"><br></td></tr><tr><td>
Anzahl Farben:</td><td>
<input size="5" name="anzahlfarben"> &nbsp; &nbsp;
Anzahl Teile:
<input size="5" name="anzahlteile">&nbsp;</td></tr><tr<td>
Mitteilung:</td><td style="text-align: left; vertical-align: top;"><textarea wrap="soft" tabindex="15" 
onkeyup="CheckLen(this)"
 onkeydown="CheckLen(this)" 
onfocus="CheckLen(this)"
 onchange="CheckLen(this)" cols="28" rows="3"
 name="mitteillungen" class="input">
</textarea></td></tr>
<tr><td style="vertical-align: middle;">
Nach- u. Vorname:</td><td>
<input size="37" name="nachvorname"></td>
</tr><tr><td>
Adresse:</td><td>
<input size="37" name="adresse">&nbsp;</td></tr>
<tr><td> 
Ort u. PLZ:</td><td>
<input size="37" name="ortplz">&nbsp;</td></tr><tr><td>
Telefon:</td><td>
<input size="37" name="telefon">&nbsp; </td></tr><tr><td> 
E-Mail:</td><td>
<input size="37" name="email"></td></tr><tr
 align="center"><td></td><td>
<input value="senden" type="submit"> &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;
<input class="input" value="Eingaben löschen" type="reset">&nbsp;</td></tr>
</tbody></table></form>
 
Ciao a tutti,

anche se vedo che il mio posting non ha richiamato molto interesse (solo 1 risposta), sono ancora qui con la speranza di trovare un po di collaborazione nel mio tentativo di risolvere questo problema.
La situazione attuale è che il Formmail ora funziona, nel senso che mi arriva la mail con allegato. pero......
1. non mi consegna i valori dei capi.
2. come mittente mi indica il mio stesso indirizzo del server e non quella
inserita dal User nel form.

Se ce qualcuno che mi può aiutare a trovare la soluzione, io ringrazio in anticipo.

buona domenica a tutti in tanto

nora61

PHP:
<?php 
// Recupero il valore dei campi del form
$stickunterlage = $_POST[' stickunterlage '];
$groesse = $_POST[' groesse '];
$anzahlfarben = $_POST[' anzahlfarben '];
$anzahlteile = $_POST[' anzahlteile '];
$mitteilung = $_POST[' mitteilung '];
$nachvorname = $_POST[' nachvorname '];
$adresse = $_POST[' adresse '];
$ortplz = $_POST[' ortplz '];
$telefon= $_POST[' telefon '];
$email = $_POST[' email '];
$anhang= $_POST[' anhang '];

$betreff = "Anfrage vom Web"; 

// Valorizzo le variabili relative all'allegato
$anhang = $_FILES['anhang']['tmp_name'];
$anhang_type = $_FILES['anhang']['type'];
$anhang_name = $_FILES['anhang']['name'];

// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($anhang))
{
// Apro e leggo il file allegato
$file = fopen($anhang,'rb');
$data = fread($file, filesize($anhang));
fclose($file);

// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));

// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $mitteilung . "\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$anhang_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";

// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";
}
else
{
$msg = $mitteilung;
}

// Invio la mail
if (mail($empfaenger, $betreff, $msg, $headers))
{
echo "<p>Ihre E-Mail wurde erfogreich gesendet. Vielen Dank für Ihre Anfrage!</p>";
}else{
echo "<p>Fehler!</p>";
}
?>
 
Per quanto riguarda il mittente devi aggiungere all'header il From:

PHP:
// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "From: $mittente\n";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

dove $mittente sarà valorizzato con l'indirizzo o il nome del mittente.
L'altro problema, sulla mancata consegna dei valori dei campi, non è molto chiaro. Quali sono i campi che non vedi? Quelli che recuperi in POST all'inizio del codice? Se così fosse non vedo alcun settaggio di tali dati all'interno del corpo della mail.
 
per ciò che riguarda valori non trasmessi, ce ne uno inserito "mitteilung"

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $mitteilung . "\n\n";

ma non mi da nulla nella mail
 
scusa cabio colore 0:)

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $mitteilung . "\n\n";
 
ok piano, piano ci sto arrivando.... qundi adesso mi vengono trasmessi tutti i dati. Il problema era che cera uno spazio di troppo:
cosi:
$stickunterlage = $_POST[' stickunterlage '];

invece di cosi:
$stickunterlage = $_POST['stickunterlage'];

e poi infatti andavano inseriti nel corpo del mail

ora quello che non funziona ancora é:

1. che non mi da nulla come mittente

2. che non mi porta sul file html inserito nel $redirect

questa é la nuova versione del script:

PHP:
<?php 
// Recupero il valore dei campi del form
$stickunterlage = $_POST['stickunterlage'];
$groesse = $_POST['groesse'];
$anzahlfarben = $_POST['anzahlfarben'];
$anzahlteile = $_POST['anzahlteile'];
$mitteilung = $_POST['mitteilung'];
$nachvorname = $_POST['nachvorname'];
$adresse = $_POST['adresse'];
$ortplz = $_POST['ortplz'];
$telefon= $_POST['telefon'];
$email = $_POST['email'];
$anhang= $_POST['anhang'];
$betreff="Anfrage vom Web"; 


$redirect ="http://www.willis-stickereien.ch/bestädigunganfrage.html";

// Valorizzo le variabili relative all'allegato
$anhang = $_FILES['anhang']['tmp_name'];
$anhang_type = $_FILES['anhang']['type'];
$anhang_name = $_FILES['anhang']['name'];


// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($anhang))
{
// Apro e leggo il file allegato
$file = fopen($anhang,'rb');
$data = fread($file, filesize($anhang));
fclose($file);

// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));

// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "From: $mittente\n"; 
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";


// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $stickunterlage . "\n\n";
$msg .= $groesse . "\n\n";
$msg .= $anzahlfarben . "\n\n";
$msg .= $anzahlteile . "\n\n";
$msg .= $mitteilung . "\n\n";
$msg .= $nachvorname . "\n\n";
$msg .= $adresse . "\n\n";
$msg .= $ortplz . "\n\n";
$msg .= $telefon . "\n\n";
$msg .= $email . "\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$anhang_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";

// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";

}else{
$msg = $mitteilung;
}

// Invio la mail
if (mail($empfaenger, $betreff, $msg, $headers))
{
echo "<p>Ihre E-Mail wurde erfogreich gesendet. Vielen Dank für Ihre Anfrage!</p>";
}else{
echo "<p>Fehler!</p>";
}
?>


ps: quando tutto funzionerà, vi inserisco il PhP e il html cosi se qualcuno ne ha bisogno lo copia per inserirlo nel suo sito.
 
ecco qui ora funziona tutto alla perfezione e vi metto il codice da copiare.


Qui il codice PHP:
PHP:
<?php 
// Recupero il valore dei campi del form
$stickunterlage = $_POST['stickunterlage'];
$groesse = $_POST['groesse'];
$anzahlfarben = $_POST['anzahlfarben'];
$anzahlteile = $_POST['anzahlteile'];
$mitteilung = $_POST['mitteilung'];
$nachvorname = $_POST['nachvorname'];
$adresse = $_POST['adresse'];
$ortplz = $_POST['ortplz'];
$telefon= $_POST['telefon'];
$email = $_POST['email'];
$anhang= $_POST['anhang'];

$soggetto="lo puoi definire come vuoi"; 

//Se non hai creato una pagina html di conferma puoi inserire piu giu
//questo codice: echo "<p>La sua mail e stata inviata corretamente!</p>";
//}else{
//echo "<p>Fehler!</p>";
header ("Location: http://www.tuodominio.xx/mailconferma.html");

// Valorizzo le variabili relative all'allegato
$anhang = $_FILES['anhang']['tmp_name'];
$anhang_type = $_FILES['allegato']['type'];
$anhang_name = $_FILES['allegato']['name'];

// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($allegato))
{
// Apro e leggo il file allegato
$file = fopen($allegato,'rb');
$data = fread($file, filesize($allegato));
fclose($file);

// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));

// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "From: $email\n"; 
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";

// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Questa è la parte "testuale" del messaggio. Devi riprendere tutti i 
//capi del form che vuoi ricevere nella mail come li hai definiti piu sopra
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $stickunterlage . "\n\n";
$msg .= $groesse . "\n\n";
$msg .= $anzahlfarben . "\n\n";
$msg .= $anzahlteile . "\n\n";
$msg .= $mitteilung . "\n\n";
$msg .= $nachvorname . "\n\n";
$msg .= $adresse . "\n\n";
$msg .= $ortplz . "\n\n";
$msg .= $telefon . "\n\n";
$msg .= $email . "\n\n";

// Metto il separatore
$msg .= "--{$mime_boundary}\n";

// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$anhang_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";

// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";

}else{
$msg = $mitteilung;
}

// Invio la mail
if (mail($empfaenger, $betreff, $msg, $headers))
{
//qui puoi  inserire il codice come indicato sopra nel caso che non hai
//una pagina di conferma html
}
?>


Qui il codice html:

HTML:
<form action="formmail.php" method="post"
 enctype="multipart/form-data">
<input name="destinatario" value="tua@mail.xx" 
type="hidden">

<table border="0" cellpadding="2" cellspacing="5">
<tbody><tr><td>
Vorlage:<br>
Formate:</td>
<td>
<input name="allegato" type="file">
<br>
TlF, JPG,&nbsp;GIF,&nbsp;BMP, PNG, PDF, PSD </td></tr>
<tr><td>
Stickunterlage:<br><br>Grösse in mm:</td>
<td>
<select name="stickunterlage">
<option>..................................</option>
<option>Jeans</option>
<option>T-Shirt</option>
<option>Pullover</option>
<option>Frottewäsche</option>
<option>Leintücher</option>
<option>Autositzbezüge</option>
<option value="">Andere</option>
</select><br><br>
<input size="5" name="groesse"><br></td></tr>
<tr><td>
Anzahl Farben:</td><td>
<input size="5" name="anzahlfarben"> 
&nbsp; &nbsp;
Anzahl Teile:
<input size="5" name="anzahlteile">&nbsp;</td></tr>
<tr><td>
Mitteilung:</td><td
 style="text-align: left; vertical-align: top;">
<textarea wrap="soft" tabindex="15" 
onkeyup="CheckLen(this)"
 onkeydown="CheckLen(this)" 
onfocus="CheckLen(this)"
 onchange="CheckLen(this)" 
cols="28" rows="3"
 name="mitteilung" class="input">
</textarea></td></tr>
<tr><td style="vertical-align: middle;">
Nach- u. Vorname:</td><td>
<input size="37" name="nachvorname"></td></tr>
<tr><td>
Adresse:</td><td>
<input size="37" name="adresse">&nbsp;</td></tr><
tr><td> 
Ort u. PLZ:</td><td>
<input size="37" name="ortplz">&nbsp;</td></tr>
<tr><td>
Telefon:</td><td><input size="37" name="telefon">&nbsp; </td></tr>
<tr><td> 
E-Mail:</td><td>
<input size="37" name="email"></td></tr>
<tr align="center"><td></td><td>
<input value="senden" type="submit"> 
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<input class="input" value="Eingaben löschen" type="reset"></form>
&nbsp;</td></tr>
</tbody></table>


Grazie per l'aiuto e buone feste a tutti

Nora
 

Discussioni simili