Results 1 to 2 of 2

Thread: Multi-MailForm + Attachment Fix (Please Help)

  1. #1
    Join Date
    Mar 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Multi-MailForm + Attachment Fix (Please Help)

    Hi all,
    I have inherited a devil of a job which i hope someone can help with.
    I have no PHP experience but have used perl form-mail before.
    My clients site was dropped/lost by the hosting company, i was left with an incomplete local copy to upload and fix.

    My problem is as follows:
    The site has a PHP script spread over 3 pages (Multi-Form),
    including file upload/attachment section .

    The form seems to work to an extent, including uploading the attachment to a temporary directory on the server, however it doesn't email/send it anywhere!

    I'm sure that this part of the script is missing.

    I am uncertain if the script is a free one or a bespoke.

    Any input will be greatly received.

    Many thanks,
    G.

    PS: i was unable to post all the code (to long),
    but here is the url: http://artblox.co.uk/order_form_1.php
    Last edited by goonster; 04-09-2009 at 12:57 PM. Reason: missed a bit

  2. #2
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    I had a lot of trouble with sending mail attachments when I was making a form that would email a member of my site a .wav file. This is my code in full - hope it helps.

    ps. make a folder to hold the attachment. mines named 'uploads'. Also the email for my sites member was stored in a file called email.txt.

    ---
    the form displayed to the user
    ---
    Code:
    <input type="hidden" name="MAX_FILE_SIZE" value="900000"/>
    <table border="0" bgcolor="blue" width="350height="300" align="left">
     <tr>
      <td>Full name: 
      <td><input type="text" name="name" tabindex="1" size="28"></td>
     </tr>
     <tr>
      <td>E-Mailing address:</td>
      <td><input type="text" name="mail" tabindex="2" size="28"></td>
     </tr>
     <tr>
      <td>Phone number:</td>
      <td><input type="text" name="phone" tabindex="3" size="28"></td>
     </tr>
     <tr>
      <td>Any initial question:<br><br><br><br></td>
      <td><textarea name="question" tabindex="4" rows="4" cols="23" WRAP=HARD></textarea></td>
     </tr>
     <tr>
      <td>Upload sample:</td>
      <td><input type="file" name="file" tabindex="5"></td>
     </tr>
    </table>
    <br><br><br><br><br><br><br><br><br><br><br><br>
    <input type="submit" value="Submit Sample" name="submit" tabindex="6">
    </form>
    --------
    submit_sample.php
    --------

    Code:
    <?php
    	//uploading the files
    	//-----------------------------------------------------------------
    if (($_FILES["file"]["type"] == "audio/wav") && ($_FILES["file"]["size"] < 900000))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        $samplestored = move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES["file"]["name"]) . "<br />";
        $samplewav = "uploads/" . $_FILES["file"]["name"];
        }
      }
    else
      {
      echo "Invalid file type or size";
      }
    ?>
    
    <?php 
    		$name = $_POST['name'];
    		$phone = $_POST['phone'];
    		$question = $_POST['question'];
    		$mail = $_POST['mail'];
    		$message = "Someone has sent a sample through the website form.<br><br> Name: $name <br> Email: $mail <br> Phone: $phone <br> question: $question" ;
    
    $fileatt = "$samplewav"; // Path to the file 
    $fileatt_type = "audio/wav"; // File Type 
    $fileatt_name = $_FILES["file"]["name"]; // Filename that will be used for the file as the attachment 
    
    $email_from = "mysite"; // Who the email is from 
    $email_subject = "Your attached file"; // The Subject of the email 
    $email_message = "Thanks for useing mysite.com <br>";
    $email_message .= "$message"; // Message that the email has in it 
    
    $email_to = file_get_contents("email.txt"); // Who the email is to 
    
    $headers = "From: ".$email_from; 
    
    $file = fopen($fileatt,'rb'); 
    $data = fread($file,filesize($fileatt)); 
    fclose($file); 
    
    $semi_rand = md5(time()); 
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
    
    $headers .= "\nMIME-Version: 1.0\n" . 
    "Content-Type: multipart/mixed;\n" . 
    " boundary=\"{$mime_boundary}\""; 
    
    $email_message .= "This is a multi-part message in MIME format.\n\n" . 
    "--{$mime_boundary}\n" . 
    "Content-Type:text/html; charset=\"iso-8859-1\"\n" . 
    "Content-Transfer-Encoding: 7bit\n\n" . 
    $email_message .= "\n\n"; 
    
    $data = chunk_split(base64_encode($data)); 
    
    $email_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"; 
    
    $ok = @mail($email_to, $email_subject, $email_message, $headers); 
    unlink($samplewav);
    
    if($ok) { 
    echo "<font face=verdana size=2><center>Your sample has been submitted.<br>
    Click <a href=\"#\" onclick=\"history.back();\">here</a> to return.</center>";
    
    } else { 
    die("Sorry but the email could not be sent. Please go back and try again!"); 
    } 
    ?>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •