Autor Zpráva
gabael
Profil
Zdravím vospolok,

potrebujem pomôcť s kontaktným formulárom, ktorý dokáže odoslať email s prílohou.
Google mi dokázal trošku pomôcť, a našiel som niečo takéto:

        <?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

   // we'll begin by assigning the To address and message subject
   $to="gabor.jenei@gmail.com";
   $subject="Mába e-mail";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $from\r\n" .
   "MIME-Version: 1.0\r\n" .
      "Content-Type: multipart/mixed;\r\n" .
      " boundary=\"{$mime_boundary}\"";

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail
   $message="Mába üzenet";

   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message = "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"utf-8\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
     
            // open the file for a binary read
            $file = fopen($tmp_name,'rb');
     
            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));

            // close the file
            fclose($file);
     
            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }
     
         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--\n";
   // now we just send the message
   if (@mail($to, $subject, $message, $headers, $phone))
      echo "<p align='center'><strong>Üzenet elküldve!</strong></p><br>
            <p align='center'><strong>Köszönjük!</strong></p>";
   else
      echo "<p align='center'><strong>Nem sikerült elküldeni</strong></p>";
} else {
?>
      </p>
      <p class="p-BOLD">Email k&uuml;ld&eacute;se:</p>
      <p>K&eacute;rj&uuml;k, azt az el&eacute;rhetős&eacute;g&eacute;t adja meg, ahova a v&aacute;laszt k&eacute;ri!</p><hr>
      <form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="form1">
        <table width="650" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td align="right" valign="middle"><p>Az &Ouml;n neve:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromname" type="text" class="inputfield" size="40">
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>Az &Ouml;n email c&iacute;me:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromemail" type="text" class="inputfield" size="40">
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>Az &Ouml;n telefonsz&aacute;ma:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromphone" type="text" class="inputfield" id="fromphone" size="40">
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>&Uuml;zenet:</p></td>
    <td align="left" valign="middle"><p>
      <textarea name="frommessage" class="message" id="frommessage"></textarea>
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>File 1:</p></td>
    <td align="left" valign="middle"><p>
      <input name="file1" type="file" class="inputfield" size="40">
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>File 2:</p></td>
    <td align="left" valign="middle"><p>
      <input name="file2" type="file" class="inputfield" size="40">
    </p></td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle"><p>
      <input type="submit" name="Submit" value="&Uuml;zenet k&uuml;ld&eacute;se">
    </p></td>
    </tr>
        </table>
      </form>
      <?php } ?>

tento formulár som už "osadil" na web : www.cisteriesenie.sk/Maba/contact/contact.php
Je to celkom OK, až na to, že si neviem poradiť s doplnením dvoch ďalších inputov ( telefon a správa).

Ďalej:
- po vyplnení formulára (meno a mailova adresa) mi príde do poštoveho klienta mail s prílohou, čo je fasa, ale odosielateľa mi ukazuje veľmi čudne:
Gábor Jénei<gabor.jenei@forex.eu.sk> [=?ISO-8859-1?Q?G=E1bor_J=E9nei<gabor.jenei@forex.eu.sk>?=]

A v poslednom rade, by som rád do tohto kódu vložil to, že email a meno sú povinné polia.

Vopred ďakujem za každú pomoc.
SwimX
Profil
gabael:
A v poslednom rade, by som rád do tohto kódu vložil to, že email a meno sú povinné polia.
za
if ($_SERVER['REQUEST_METHOD']=="POST"){
vlož něco takového to
if ( empty ( $_POST ['nazevpovinehoprvku'] ) ) echo "toto je povine pole"; else { zbytek kodu }

doplnění prvků:
dole v html stačí zkopírovat řádky tabulky a přejmenovat inputy

v php kodu potom zde radek 24
 $message="Mába üzenet";
začíná vlastní zpráva. Cokoliv chceš do ní jde přidat stylem:
 $message .="Telefon: " . $_POST [ 'telefon' ] . "\r\n";

a co set týče kódování předmětu a zprávy, tak se koukni do FAQU zdejšího, je to tam krásně popsáno.
gabael
Profil
SwimX:

Úvodom ďakujem za pomoc. V PHP nie som veľmi dobrý. Zmenil som kód na niečo takéto avšak formulár sa už vôbec na webe ani nezobrazí.
Aby si to možno kus lepšie pochopil a zároveň mi pomohol urobil som aj slovenskú verziu tohto formulára: http://www.cisteriesenie.sk/Maba/SK-SITE/kontakt.php
Nechápem to, prečo to nefunguje. Tento typ formulára ma potešil z dôvodu, že nepotrebuje vytvárať v roote priečinok s oprávneniami, kde nahráva odosielané súbory.

Za pomoc, vopred ďakujem.

        <?php
        
        $meno     = $_POST['fromname'];
        $email    = $_POST['fromemail'];
        $telefon  = $_POST['fromphone'];
        $sprava   = $_POST['frommessage'];
        $d        = date('l dS \of F Y h:i:s A');
        
if ($_SERVER['REQUEST_METHOD']=="POST"){
    
    if ( empty ($meno) || empty($email))
    
    {
     echo
     '<p align="center"><strong>Prepáčte, ale všetky polia označené * sú povinné pre vyplnenie.</strong></p>';
}
    else
    {
     (@mail($to, $subject, $message, $headers, $phone));
     print '<p><center>Ďakujeme '.$meno.' za Váš záujem.<br>Naši pracovníci Vás budú kontaktovať v dohľadnej dobe.</center></p>';
}
   // we'll begin by assigning the To address and message subject
   $to="gabor.jenei@gmail.com";
   $subject="Mába e-mail";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $from\r\n" .
   "MIME-Version: 1.0\r\n" .
      "Content-Type: multipart/mixed;\r\n" .
      " boundary=\"{$mime_boundary}\"";

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail

   $message     .= 'Meno a Priezvisko: '.$meno."\n";
   $message     .= 'Email: '.$email."\n";
   $message     .= 'Telefon: '.$telefon."\n";
   $message     .= 'Správa: '.$sprava."\n";
   $message     .= 'Dátum a čas: '.$d;

   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message = "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"utf-8\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
     
            // open the file for a binary read
            $file = fopen($tmp_name,'rb');
     
            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));

            // close the file
            fclose($file);
     
            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }
     
         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--\n";
   // now we just send the message
?>
      </p>
      <p class="p-BOLD">Kontaktný formulár:</p>
      <p>Využite náš kontaktný formulár. Napíšte nám Vaše požiadavky, prípadne priložte Vaše fotky o predstave.<br />
      (polia označené <span class="bold-red-big">*</span> sú povinné pre vyplnenie) </p>
      <hr>
      <form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" 
   enctype="multipart/form-data" name="form1">
        <table width="650" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td align="right" valign="middle"><p>meno a priezvisko:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromname" type="text" class="inputfield" size="40">    
      <span class="bold-red-big">*</span></p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>e-mail:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromemail" type="text" class="inputfield" size="40">    
      <span class="bold-red-big">*</span></p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>telefón:</p></td>
    <td align="left" valign="middle"><p>
      <input name="fromphone" type="text" class="inputfield" id="fromphone" size="40">    
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>správa:</p></td>
    <td align="left" valign="middle"><p>
      <textarea name="frommessage" class="message" id="frommessage"></textarea>
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>Súbor 1:</p></td>
    <td align="left" valign="middle"><p>
      <input name="file1" type="file" class="inputfield" size="40">    
    </p></td>
  </tr>
  <tr>
    <td align="right" valign="middle"><p>Súbor 2:</p></td>
    <td align="left" valign="middle"><p>
      <input name="file2" type="file" class="inputfield" size="40">    
    </p></td>
  </tr>
  <tr>
    <td colspan="2" align="center" valign="middle"><p>
      <input type="submit" name="Submit" value="Odoslať">    
    </p></td>
    </tr>
        </table>
      </form>
      <?php } ?>
panther
Profil
gabael:
na ř. 19 odesíláš (pokousíš se odeslat) e-mail, ale dané proměnné neexistují, vytváříš je až někde níž.

Na ř. 43 budeš mít nedefinovanou proměnnou (varování), tam ta tečka před rovnítko nepatří (na dalších řádcích, v momentě, kdy proměnná existuje, už je tam tečka správně).
gabael
Profil
Ďakujem, takto to funguje perfektne !

Akurát by som poteboval aby meno a email boli povinné polia.


        <?php
        
        $meno     = $_POST['fromname'];
        $email    = $_POST['fromemail'];
        $telefon  = $_POST['fromphone'];
        $sprava   = $_POST['frommessage'];
        $d        = date('l dS \of F Y h:i:s A');
        
if ($_SERVER['REQUEST_METHOD']=="POST"){
    
   // we'll begin by assigning the To address and message subject
   $to="gabor.jenei@gmail.com";
   $subject="Mába e-mail";

   // get the sender's name and email address
   // we'll just plug them a variable to be used later
   $from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

   // generate a random string to be used as the boundary marker
   $mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

   // now we'll build the message headers
   $headers = "From: $from\r\n" .
   "MIME-Version: 1.0\r\n" .
      "Content-Type: multipart/mixed;\r\n" .
      " boundary=\"{$mime_boundary}\"";

   // here, we'll start the message body.
   // this is the text that will be displayed
   // in the e-mail

   $message     .= 'Meno a Priezvisko: '.$meno."\n";
   $message     .= 'Email: '.$email."\n";
   $message     .= 'Telefon: '.$telefon."\n";
   $message     .= 'Správa: '.$sprava."\n";
   $message     .= 'Dátum a čas '.$d;

   // next, we'll build the invisible portion of the message body
   // note that we insert two dashes in front of the MIME boundary 
   // when we use it
   $message = "This is a multi-part message in MIME format.\n\n" .
      "--{$mime_boundary}\n" .
      "Content-Type: text/plain; charset=\"utf-8\"\n" .
      "Content-Transfer-Encoding: 7bit\n\n" .
   $message . "\n\n";

   // now we'll process our uploaded files
   foreach($_FILES as $userfile){
      // store the file information to variables for easier access
      $tmp_name = $userfile['tmp_name'];
      $type = $userfile['type'];
      $name = $userfile['name'];
      $size = $userfile['size'];

      // if the upload succeded, the file will exist
      if (file_exists($tmp_name)){

         // check to make sure that it is an uploaded file and not a system file
         if(is_uploaded_file($tmp_name)){
     
            // open the file for a binary read
            $file = fopen($tmp_name,'rb');
     
            // read the file content into a variable
            $data = fread($file,filesize($tmp_name));

            // close the file
            fclose($file);
     
            // now we encode it and split it into acceptable length lines
            $data = chunk_split(base64_encode($data));
         }
     
         // now we'll insert a boundary to indicate we're starting the attachment
         // we have to specify the content type, file name, and disposition as
         // an attachment, then add the file content.
         // NOTE: we don't set another boundary to indicate that the end of the 
         // file has been reached here. we only want one boundary between each file
         // we'll add the final one after the loop finishes.
         $message .= "--{$mime_boundary}\n" .
            "Content-Type: {$type};\n" .
            " name=\"{$name}\"\n" .
            "Content-Disposition: attachment;\n" .
            " filename=\"{$fileatt_name}\"\n" .
            "Content-Transfer-Encoding: base64\n\n" .
         $data . "\n\n";
      }
   }
   // here's our closing mime boundary that indicates the last of the message
   $message.="--{$mime_boundary}--\n";
   // now we just send the message
   if (@mail($to, $subject, $message, $headers))
      echo "<p align='center'><strong>Správa úspešne odoslaná!</strong></p><br>
            <p align='center'><strong>Ďakujeme!</strong></p>";
   else
      echo "<p align='center'><strong>Správu nebolo možné odoslať!</strong></p>";
} else {
    
?>

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0