need little help with script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

need little help with script

Post by juline »

hi people,

i would appriciate if anyone can help me. i have this form which would allowe to attach a file, but the script has a mistake. it will not do anything if there is no attached file. how can i make it to work weather there is a file to be attached or not ??? :cry:

this is the html form :

Code: Select all

<FORM name=&quote;cForm&quote; action=&quote;sendeanfrage.php&quote; enctype=&quote;multipart/form-data&quote; method= &quote;post&quote;>
<TABLE border=0 width=&quote;442&quote;>
  <TBODY>
  <TR>
    <TD width=&quote;203&quote;>Firma / Behörde:</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;firma&quote; size=&quote;30&quote; maxlength=&quote;30&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Vorname*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;vorname&quote; size=&quote;25&quote; maxlength=&quote;25&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Name*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;name&quote; size=&quote;25&quote; maxlength=&quote;25&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Strasse, Nr.*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;strasse&quote; size=&quote;30&quote; maxlength=&quote;30&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>PLZ*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;plz&quote; size=&quote;5&quote; maxlength=&quote;5&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Ort*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;ort&quote; size=&quote;15&quote; maxlength=&quote;15&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Tel.*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;tel&quote; size=&quote;13&quote; maxlength=&quote;13&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Fax</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;fax&quote; size=&quote;13&quote; maxlength=&quote;13&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>E-Mail*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;email&quote; size=&quote;20&quote; maxlength=&quote;20&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Quelltextinhalt / Fachbereich*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;inhalt&quote; size=&quote;20&quote; maxlength=&quote;20&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Übersetzungszweck / Zielgruppe</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;zweck&quote; size=&quote;30&quote; maxlength=&quote;30&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Anzahl Normzeilen*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;normzeilen&quote; size=&quote;5&quote; maxlength=&quote;5&quote;>   (55 Anschläge pro Zeile)</TD>
    </TR>
  <TR>
    <TD width=&quote;203&quote;>Quellsprache*</TD>
    <TD width=&quote;229&quote;><SELECT NAME=&quote;qsprache&quote;>
         <OPTION>Bitte wählen Sie...</OPTION>
         <OPTION>Afghanisch</OPTION>
        .......
             </SELECT> </TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Zielsprache*</TD>
    <TD width=&quote;229&quote;><SELECT NAME=&quote;zsprache&quote;>
         <OPTION>Bitte wählen Sie...</OPTION>
         <OPTION>Afghanisch</OPTION>
    ........
             </SELECT> </TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Abgabe des Quelltextes*</TD>
    <TD width=&quote;229&quote;><INPUT name=&quote;abgabeq&quote; size=&quote;10&quote; maxlength=&quote;10&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Abgabeart (Quelltext)*</TD>
    <TD width=&quote;229&quote;><SELECT NAME=&quote;abgabeart&quote; class=&quote;select&quote;>
             <OPTION>-----</OPTION>
             <OPTION>Fax</OPTION>
             <OPTION>Post</OPTION>
             <OPTION>E-Mail</OPTION>
             </SELECT></TD></TR>
  <TR>
    <TD width=&quote;203&quote;><input type=&quote;hidden&quote; name=&quote;MAX_FILE_SIZE&quote; value=&quote;3000000&quote;>Datei hochladen</TD>
    <TD width=&quote;229&quote;>
    <input name=&quote;file&quote; type=&quote;file&quote; size=&quote;15&quote; maxlength=&quote;15&quote;></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>gewünschte Übersetzungsdauer*</TD>
    <TD width=&quote;229&quote;><SELECT NAME=&quote;dauer&quote; class=&quote;select&quote;>
             <OPTION>-----</OPTION>
             <OPTION>24h</OPTION>
             <OPTION>1-2 Tage</OPTION>
             <OPTION>3 < Tage</OPTION>
             </SELECT></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Lieferart*</TD>
    <TD width=&quote;229&quote;><SELECT NAME=&quote;lieferart&quote; class=&quote;select&quote;>
             <OPTION>-----</OPTION>
             <OPTION>Fax</OPTION>
             <OPTION>Post</OPTION>
             <OPTION>E-Mail</OPTION>
             </SELECT> </TD></TR>
  <TR>
    <TD width=&quote;203&quote;>Zusätzliche Leistungen<br> erforderlich?</TD>
    <TD width=&quote;229&quote;>
    <TEXTAREA cols=&quote;26&quote; name=&quote;zusatz&quote; rows=&quote;5&quote; maxlength=&quote;100&quote; input>Beglaubigung, Korrektur, Layoutierung, Apostille, etc.....</TEXTAREA></TD></TR>
  <TR>
    <TD width=&quote;203&quote;>sonstige Vermerke:</TD>
    <TD width=&quote;229&quote;>
    <TEXTAREA cols=&quote;26&quote; name=&quote;sonstiges&quote; rows=&quote;5&quote; maxlength=&quote;100&quote; input></TEXTAREA><br><br></TD></TR>
  <tr>
 <td align=&quote;center&quote; width=&quote;203&quote;> </td>
 <td align=&quote;center&quote; width=&quote;229&quote;>
 <INPUT border=0 type=submit value=&quote;senden&quote; width=&quote;73&quote; height=&quote;29&quote;>
  
<INPUT border=0 type=reset  value=&quote;loeschen&quote;  width=&quote;73&quote; height=&quote;29&quote;></td>
  </tr>
   </TBODY>
   </TABLE>
</FORM>
and this is the php-file :

Code: Select all

<?php

	$firma = $HTTP_POST_VARS['firma'];
	$vorname = $HTTP_POST_VARS['vorname'];
	$name = $HTTP_POST_VARS['name'];
	$strasse = $HTTP_POST_VARS['strasse'];
	$plz = $HTTP_POST_VARS['plz'];
	$ort = $HTTP_POST_VARS['ort'];
	$tel = $HTTP_POST_VARS['tel'];
	$fax = $HTTP_POST_VARS['fax'];
	$email = $HTTP_POST_VARS['email'];
	$inhalt = $HTTP_POST_VARS['inhalt'];
	$zweck = $HTTP_POST_VARS['zweck'];
	$normzeilen = $HTTP_POST_VARS['normzeilen'];		
	$qsprache = $HTTP_POST_VARS['qsprache'];
	$zsprache = $HTTP_POST_VARS['zsprache'];
	$abgabeq = $HTTP_POST_VARS['abgabeq'];
	$abgabeart = $HTTP_POST_VARS['abgabeart'];
	$dauer = $HTTP_POST_VARS['dauer'];													
	$lieferart = $HTTP_POST_VARS['lieferart'];	
	$zusatz = $HTTP_POST_VARS['zusatz'];
	$sonstiges = $HTTP_POST_VARS['sonstiges'];		
	
	$uploaddir = 'files/uploads/'; 
	$filename=$_FILES['file']['name']; 
  
	if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir."$filename")) 
	{ 
       
   $anhang=fopen("files/uploads/$filename", r); 
   $groesse=filesize("files/uploads/$filename"); 
   $anhangdatei=fread($anhang,$groesse); 
   $anhang_email=chunk_split(base64_encode($anhangdatei)); 
   fclose($anhang); 
    
   $Empfaenger="info@thisthat.com"; 
   $Betreff = "Anfrage"; 
   $Nachricht = "Folgende Anfrage wurde gestellt:
	 <br>Firma:  $firma
	 <br>Vorname:  $vorname 
	 <br>Name:  $name 
	 <br>Strasse:  $strasse 
	 <br>PLZ:  $plz
	 <br>Ort:  $ort
	 <br>Tel:  $tel
	 <br>Fax:  $fax	 	 	  	 	  	 	 
	 <br>E-Mail Adresse:  $email 
	 <br>Qelltextinhalt / Fachbereich:  $inhalt 	 
	 <br>Zielgruppe / Übersetzungszweck:  $zweck
	 <br>Anzahl Normzeilen:  $normzeilen	 
	 <br>Quellsprache:  $qsprache 	 
	 <br>Zielsprache:  $zsprache
	 <br>Abgabe des Quelltext:  $abgabeq	 
	 <br>Abgabeart (Quelltext):  $abgabeart
	 <br>Gewünschte Übersetzungsdauer:  $dauer
	 <br>Lieferart:  $lieferart	
	 <br>Zusätzliche Leistungen erforderlich?:
	 <br>$zusatz
	 <br>sonstige Vermerke:
	 <br>$sonstiges<br><br>";
	 
   $Dateiname = "files/uploads/$filename"; 
   $DateinameMail = "$filename"; 
    
   $Header .= "From: ".$name." ".$vorname." <".$email.">"; 
   $Header .= "\n";    
   $Header .= "Cc: ";
   $Header .= "\n";    
   $Header .= "Bcc: info@thistaht2.com";

  
   $bound = strtoupper(md5(uniqid(time()))); 
   $Header .= "\n"; 
   $Header .= "MIME-Version: 1.0"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: multipart/mixed; boundary=$bound"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";
   $Header .= "Content-Type: text/html; charset=iso-8859-1";
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= $Nachricht; 
   $Header .= "\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";
   $Header .= "Content-Type: $file_type"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: $file_type; name=$DateinameMail"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: base64"; 
   $Header .= "\n"; 
   $Header .= "Content-Disposition: attachment; filename=$DateinameMail"; 
   $Header .= "\n\n"; 
   $Header .= chunk_split(base64_encode(fread(fopen($Dateiname, "r"), filesize($Dateiname)))); 
   $Header .= "\n"; 
   $Header .= "--$bound--"; 
 
   mail ($Empfaenger, $Betreff, "", $Header);
} 
?>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Well, some headers in the email message are unnecessary when you don't have an attachment. You'll have to get rid of some of them when there is no attachment. Do you know what all those headers mean?
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

actually not really.
can you advice me how to do ?
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Could you please tell us the error that you are receiving.
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

well, there is no error message. the script just does nothing at all.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Wel for starters you have no message in there to notify the sender of a successful mailing. Just before the last closing bracket write:

Code: Select all

echo 'The mail was successfully sent.'
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

see, it works if you attach anything but it does nothing if you dont attache anything.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Ah, two minutes and I will rewrite and post it.
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

Joe wrote:Wel for starters you have no message in there to notify the sender of a successful mailing. Just before the last closing bracket write:

Code: Select all

echo 'The mail was successfully sent.'
i add this and wont work too:

Code: Select all

require ("dankeanfrage.html");
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

For the php script try the following code:

Code: Select all

<?php
 
    $firma = $HTTP_POST_VARS['firma'];
    $vorname = $HTTP_POST_VARS['vorname'];
    $name = $HTTP_POST_VARS['name'];
    $strasse = $HTTP_POST_VARS['strasse'];
    $please = $HTTP_POST_VARS['please'];
    $ort = $HTTP_POST_VARS['ort'];
    $tel = $HTTP_POST_VARS['tel'];
    $fax = $HTTP_POST_VARS['fax'];
    $email = $HTTP_POST_VARS['email'];
    $inhalt = $HTTP_POST_VARS['inhalt'];
    $zweck = $HTTP_POST_VARS['zweck'];
    $normzeilen = $HTTP_POST_VARS['normzeilen'];        
    $qsprache = $HTTP_POST_VARS['qsprache'];
    $zsprache = $HTTP_POST_VARS['zsprache'];
    $abgabeq = $HTTP_POST_VARS['abgabeq'];
    $abgabeart = $HTTP_POST_VARS['abgabeart'];
    $dauer = $HTTP_POST_VARS['dauer'];                                                    
    $lieferart = $HTTP_POST_VARS['lieferart'];    
    $zusatz = $HTTP_POST_VARS['zusatz'];
    $sonstiges = $HTTP_POST_VARS['sonstiges'];        
    
    $uploaddir = 'files/uploads/'; 
    $filename=$_FILES['file']['name']; 
  
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir."$filename")) 
    { 
       
   $anhang=fopen("files/uploads/$filename", r); 
   $groesse=filesize("files/uploads/$filename"); 
   $anhangdatei=fread($anhang,$groesse); 
   $anhang_email=chunk_split(base64_encode($anhangdatei)); 
   fclose($anhang); 
    
   $Empfaenger="info@thisthat.com"; 
   $Betreff = "Anfrage"; 
   $Nachricht = "<html>
     <head>
     <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"> 
     </head>
     <body>
     Folgende Anfrage wurde gestellt:
     <br>Firma:  $firma
     <br>Vorname:  $vorname 
     <br>Name:  $name 
     <br>Strasse:  $strasse 
     <br>please:  $please
     <br>Ort:  $ort
     <br>Tel:  $tel
     <br>Fax:  $fax                                     
     <br>E-Mail Adresse:  $email 
     <br>Qelltextinhalt / Fachbereich:  $inhalt      
     <br>Zielgruppe / Übersetzungszweck:  $zweck
     <br>Anzahl Normzeilen:  $normzeilen     
     <br>Quellsprache:  $qsprache      
     <br>Zielsprache:  $zsprache
     <br>Abgabe des Quelltext:  $abgabeq     
     <br>Abgabeart (Quelltext):  $abgabeart
     <br>Gewünschte Übersetzungsdauer:  $dauer
     <br>Lieferart:  $lieferart    
     <br>Zusätzliche Leistungen erforderlich?:
     <br>$zusatz
     <br>sonstige Vermerke:
     <br>$sonstiges<br><br>
     </body>
     </html>";
     
   $Dateiname = "files/uploads/$filename"; 
   $DateinameMail = "$filename"; 
    
   $Header .= "From: ".$name." ".$vorname." <".$email.">"; 
   $Header .= "\n";    
   $Header .= "Cc: ";
   $Header .= "\n";    
   $Header .= "Bcc: info@thistaht2.com";
 
  
   $bound = strtoupper(md5(uniqid(time()))); 
   $Header .= "\n"; 
   $Header .= "MIME-Version: 1.0"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: multipart/mixed; boundary=$bound"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";
   $Header .= "Content-Type: text/html; charset=iso-8859-1";
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= $Nachricht; 
   $Header .= "\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n";
   $Header .= "Content-Type: $file_type"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: 8bit"; 
   $Header .= "\n\n"; 
   $Header .= "--$bound"; 
   $Header .= "\n"; 
   $Header .= "Content-Type: $file_type; name=$DateinameMail"; 
   $Header .= "\n"; 
   $Header .= "Content-Transfer-Encoding: base64"; 
   $Header .= "\n"; 
   $Header .= "Content-Disposition: attachment; filename=$DateinameMail"; 
   $Header .= "\n\n"; 
   $Header .= chunk_split(base64_encode(fread(fopen($Dateiname, "r"), filesize($Dateiname)))); 
   $Header .= "\n"; 
   $Header .= "--$bound--"; 
 
   mail ($Empfaenger, $Betreff, "", $Header);
   echo 'Mail successfully sent.';
   } else {
     $Empfaenger="info@thisthat.com"; 
     $Betreff = "Anfrage"; 
   $Nachricht = "<html>
     <head>
     <meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"> 
     </head>
     <body>
     Folgende Anfrage wurde gestellt:
     <br>Firma:  $firma
     <br>Vorname:  $vorname 
     <br>Name:  $name 
     <br>Strasse:  $strasse 
     <br>please:  $please
     <br>Ort:  $ort
     <br>Tel:  $tel
     <br>Fax:  $fax                                     
     <br>E-Mail Adresse:  $email 
     <br>Qelltextinhalt / Fachbereich:  $inhalt      
     <br>Zielgruppe / Übersetzungszweck:  $zweck
     <br>Anzahl Normzeilen:  $normzeilen     
     <br>Quellsprache:  $qsprache      
     <br>Zielsprache:  $zsprache
     <br>Abgabe des Quelltext:  $abgabeq     
     <br>Abgabeart (Quelltext):  $abgabeart
     <br>Gewünschte Übersetzungsdauer:  $dauer
     <br>Lieferart:  $lieferart    
     <br>Zusätzliche Leistungen erforderlich?:
     <br>$zusatz
     <br>sonstige Vermerke:
     <br>$sonstiges<br><br>
     </body>
     </html>";

     $Header = "From: you@{$_SERVER['SERVER_NAME']}\r\n";
     $Header .= "Content-type: text/html\r\n";

     mail ($Empfaenger, $Betreff, $Nachricht, $Header);
     echo 'Mail successfully sent.';
   }
?>

Update at 20:47 (GMT)
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Ich bin sicher der oben Code soll arbeiten. Wenn mich nicht berührt!

Joe
juline
Forum Commoner
Posts: 37
Joined: Thu Jul 15, 2004 9:05 am

Post by juline »

wow, thanks a lot joe.
you helped me much.
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

No problem. Glad I could be of an assitance :)
Post Reply