We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    isit posible to have a "atach file" field in the emailform snippet?

    I am working on a website for a translation company that would like to have a option for ataching files when people ask for a price with the mailform.
    is this posible?

      follow me on twitter: @dimmy01
      • 7455
      • 2,204 Posts
      bumb
        follow me on twitter: @dimmy01
        • 32241
        • 1,495 Posts
        I found this while searching on google.
        I believe you can use this on snippet, and all you need to do is include them in your page.


        https://www.omidsoft.com/tutorial/formmail_attachment.html

        Attach files to your form mail using PHP

        If you are going to use a PHP form to get the data from user plus a file upload field to attach a file to that email you’re welcome.
        First create an html form and get the following information from user :
        - Email address and personal information.
        - A file upload field to get the target address of file.
        Now set the action of this form to "signup.php" with the POST method and set the value to your email address.
        Example :
        <form name=a method=POST action="signup.php" enctype="multipart/form-data" autocomplete=off>
        <input type="hidden" name="to" value="your email address">
        Now use the following code as "signup.php" :
        <?php
        // --- Create Message Text
        $form_fields=array_keys($HTTP_POST_VARS);
        $temp="Sender's IP Address = " . $REMOTE_ADDR . "\n";
        while($field=array_pop($form_fields)){
            $temp.=" $field : = $HTTP_POST_VARS[$field] \n";
        }
        
        // Read POST request params into global vars
        $to      = $_POST['to'];
        $from    = $_POST['Email'];
        $message = $temp;
        
        // Obtain file upload vars
        $fileatt      = $_FILES['File']['tmp_name'];
        $fileatt_type = $_FILES['File']['type'];
        $fileatt_name = $_FILES['File']['name'];
        
        $headers = "From: $from";
        
        if (is_uploaded_file($fileatt)) {
          // Read the file to be attached ('rb' = read binary)
          $file = fopen($fileatt,'rb');
          $data = fread($file,filesize($fileatt));
          fclose($file);
        
          // Generate a boundary string
          $semi_rand = md5(time());
          $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
        
          // Add the headers for a file attachment
          $headers .= "\nMIME-Version: 1.0\n" .
                      "Content-Type: multipart/mixed;\n" .
                      " boundary=\"{$mime_boundary}\"";
        
          // Add a multipart boundary above the plain message
          $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";
        
          // Base64 encode the file data
          $data = chunk_split(base64_encode($data));
        
          // Add file attachment to the message
          $message .= "--{$mime_boundary}\n" .
                      "Content-Type: {$fileatt_type};\n" .
                      " name=\"{$fileatt_name}\"\n" .
                      //"Content-Disposition: attachment;\n" .
                      //" filename=\"{$fileatt_name}\"\n" .
                      "Content-Transfer-Encoding: base64\n\n" .
                      $data . "\n\n" .
                      "--{$mime_boundary}--\n";
        }
        
        // Send the message
        $ok = @mail($to, "Contact", $message, $headers);
        if (!$ok) header("location:https://www.omidsoft.com");
        
        // -- Send Another Message to SENDER
        $message = '
        <html>
        <head>
        <title></title>
        <style>
        a:hover { color: red }
        </style>
        </head>
        <body link="#0000FF" vlink="#0000FF" alink="#0000FF">
        <p><font face="Verdana" size="2">Dear Valued Customer,<br>
        Your email received<br>
        Thank you.</font></p>
        <hr>
        </body>
        </html>
        ';
        
        $to = $HTTP_POST_VARS['Email'];
        $subject = "Received";
        
        $headers  = "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/html; charset=UTF-8\r\n";
        $headers .= "To: ". $to ."\r\n";
        $headers .= "From: [email protected] <[email protected]>\r\n";
        
        @mail($to, $subject, $message, $headers);
        
        // -- Goto Another Page
        header("location:https://www.omidsoft.com");
        ?>
        

        " Please note that this form is include an advanced HTML auto responder that will send a reply to the Email address field. "
        " User will be redirected to the home page of your site at last. "

        Good Luck !
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 7455
          • 2,204 Posts
          ok thanks will test this
          if any could add this as an option to the mailform that would be so cool
            follow me on twitter: @dimmy01
            • 7455
            • 2,204 Posts
            mm the code semi works no errors bu also no file attached to the mail.
            and html mail is not in html

            what could this be??
              follow me on twitter: @dimmy01