email attachment code, code is working but I want to add pro

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
plodos
Forum Newbie
Posts: 11
Joined: Wed Jan 30, 2008 12:16 pm

email attachment code, code is working but I want to add pro

Post by plodos »

form.html

Code: Select all

 
<form name="form1" method="POST" enctype="multipart/form-data"  action="sendmail.php">
<input name="to" type="text" >
<input name="subject" type="text" >
<textarea name="message" ></textarea>
<input name="Send" type="submit" value="   Send    " >
<input name="fileatt" type="file" >
</form>
 
sendmail.php

Code: Select all

 
<?php
            //get data nedeed !
            $from     = $_POST[from];
            $to       = $_POST[to];
            $subject  = $_POST[subject];
            $message  = $_POST[message];
            //replace \n with <br>
            $message = str_replace("\n", "<br>",$message);
            //report
            echo "<b><font color=#8080FF> From: $from </b><br>";
            echo "<b>To: $to </b><br>";
            echo "<b>Subject: $subject</b><br><br></font>";
            // Obtain file upload variables
            $fileatt      = $_FILES['fileatt']['tmp_name'];
            $fileatt_type = $_FILES['fileatt']['type'];
            $fileatt_name = $_FILES['fileatt']['name'];
 
            $headers = "From: $from  \n";
 
$FILE_EXTS = array('.zip','.doc','.pdf','.txt','.rar','.docx'); 
$file_name = $_FILES['fileatt']['name'];
$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));
if (!in_array($file_ext, $FILE_EXTS)){
exit("The file which was uploaded was not a valid file type.");
echo "The file which was uploaded was not a valid file type.";
}
 
 
 
           // if($_FILES['fileatt']['size'] > 0)
           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 .= "MIME-Version: 1.0\n" .
                        "Content-Type: multipart/mixed;\n" .
                        " boundary=\"{$mime_boundary}\"";
            // Add a multipart boundary above the  message
            $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" .
            $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";
             }else echo "File error!  ";
 
            //send the mail
            if(mail($to, $subject, $message,$headers))echo "<b><font color=#FF0000>Message was send!<b></font>";
            else echo "<b><font color=#FF0000>Message error!<b></font>";
 
      ?>
 
Script is working but could you check it one more time, if there is a mistake/error/bug or not!

And have you any idea, i just want to make a little animation/progress bar like "Pls wait, file is uploading"

and i dont know javascript:S

how can I do progress bar ?
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: email attachment code, code is working but I want to add pro

Post by markusn00b »

You could, using onclick of the submit button, toggle the display of a hidden div to '' (nothing) and have some text and possibly an image in there.
Post Reply