SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Submitting a file from a form

    I have searched the forums and cant seem to be able to find a solution to my problem just a lot of people who have some small problems with their own site.

    I have been trying to create a form that sends to a specific email account and also allows me to attach a file which will also go via email as an attachment, I found a CGI script but it took forever to process.

    Here is one of my forms I am working on just now :

    PHP Code:
    <fieldset>
            <
    legend>Submit your CV</legend>
            <
    FORM ACTION="recruitment_agency.php" METHOD=POST ENCTYPE="multipart/form-data">
                <
    label for="name">* Name:</label> <INPUT TYPE="text" id="name" /><br />
                <
    label for="email">* E-mail:</label> <INPUT TYPE="text" id="email" /><br />
                <
    label for="email2">* Confirm E-mail:</label> <INPUT TYPE="text" id="email2" /><br />
                <
    label for="cvupload">* File:</label><INPUT TYPE="file" id="file" /><br />
                <
    textarea name=comment rows="5" cols="40"></textarea><br />
           </
    FORM
        </
    fieldset>
        <
    class="submit"><input type="submit" name="submit" value="Submit"><input type="reset" name="Submit2" value="Clear Enquiry"></p
    And here is the php I have linked to the submit form.

    PHP Code:
    <?
    if ($submit)
    {
        if (
    $name == '')
        {
            echo 
    '<tr><td><font class=spal><center>You have not entered your name.</center></font><br><font class=spal><center>Please press your back button to add your name.</center></font></td></tr></table></td></tr></table></td></tr></table>';
            exit;
        }
        
        if(!
    ereg("^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+.)+([a-zA-z]{2,3})$",$email))
        {
            echo 
    '<tr><td><font class=spal><center>You have entered an invalid email address.</center></font><br><font class=spal><center>Please press your back button to use a valid email address.</center></font></td></tr></table></td></tr></table></td></tr></table>';
            exit;
        }
        
        if(
    $email != $email2)
        {
            echo 
    '<tr><td><font class=spal><center>The email addresses that you have entered are not the same!</center></font><br><font class=spal><center>Please press your back button to use a valid email address.</center></font></td></tr></table></td></tr></table></td></tr></table>';
            exit;
        }
        
        if (
    $comment == '')
        {
            echo 
    '<tr><td><font class=spal><center>You have not entered a comment.</center></font><br><font class=spal><center>Please press your back button to fix your comments.</center></font></td></tr></table></td></tr></table></td></tr></table>';
            exit;
        }
        
        
    $toaddress "owain@creativebridge.co.uk";
        
    $mailcontent "Name: ".$name."\n\n"
        
    ."Email: ".$email."\n\n"
        
    ."Saying on Shirt: ".$saying."\n\n"
        
    ."Color of Shirt: ".$color."\n\n"
        
    ."File Name: "$_FILES['file']['name'] ."\n\n"
        
    ."Comments: ".$comment."\n\n";
        
    $headers "From: $email";
        
        if (
    $file != '')
        {
            
    // ==============
            // Configuration
            // ==============
            
    $uploaddir "uploads";
            
    $allowed_ext "jpg, gif, png, pdf, doc";
            
    $max_size "500000";
            
    $max_height "1000";
            
    $max_width "1000";
            
    $extension pathinfo($_FILES['file']['name']);
            
    $extension $extension[extension];
            
    $allowed_paths explode(", "$allowed_ext);
            
            for(
    $i 0$i count($allowed_paths); $i++) {
                if (
    $allowed_paths[$i] == "$extension") {
                    
    $ok "1";
                }
            }
            if (
    $ok == "1")
            {
                if(
    $_FILES['file']['size'] > $max_size)
                {
                    echo 
    '<tr><td><font class=spal><center>File size is too big!</center></font><br><font class=spal><center>Please press your back button to fix your file.</center></font></td></tr></table></td></tr></table></td></tr></table>';
                    exit;
                }
                if (
    $max_width && $max_height)
                {
                    list(
    $width$height$type$w) = getimagesize($_FILES['file']['tmp_name']);
                    if(
    $width $max_width || $height $max_height)
                    {
                        echo 
    '<tr><td><font class=spal><center>File height and/or width are too big!</center></font><br><font class=spal><center>Please press your back button to fix your file.</center></font></td></tr></table></td></tr></table></td></tr></table>';
                        exit;
                    }
                
                    if(
    is_uploaded_file($_FILES['file']['tmp_name']))
                    {
                        print 
    "<tr><td><font class=spal><center>Your file has been uploaded successfully! Yay!</center></font><br>";
                    }
                
                }
            } else {
                echo 
    '<tr><td><font class=spal><center>Incorrect file extension!</center></font><br><font class=spal><center>Please press your back button to fix your file.</center></font></td></tr></table></td></tr></table></td></tr></table>';
                exit;
            }
            
    $data base64_encode(implode("",file($_FILES['file']['tmp_name'])));
            
    $random_letters md5(time());
            
    $mime_boundary "==Multipart_Boundary_x{$random_letters}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; charset=\"iso-8859-1\"\n" .
            
    "Content-Transfer-Encoding: 7bit\n\n" $mailcontent "\n\n";
            
            
    $email_message .= "--{$mime_boundary}\n" .
            
    "Content-Type: {$file_type};\n" .
            
    " name=\"{$file_name}\"\n" .
            
    "Content-Transfer-Encoding: base64\n\n" .
            
    $data "\n\n" .
            
    "--{$mime_boundary}--\n";
        } else {
            
    $email_message .= $mailcontent;
        }
            

        
        
        
        
    mail($toaddress$topics$email_message$headers);
        echo 
    '<tr><td><font class=spal>&nbsp;&nbsp;&nbsp;&nbsp;Thank you for contacting us. We will respond to you within the next 24 hours. Please feel free to contact us with any further questions that you may have.</td></tr>';
        echo 
    '</table></td></tr><tr><td height=20><img height=20 width=1 src=spacer.gif></td></tr></table></td></tr></table>';
        exit;
    }
    ?>

    The submit doesnt work and on another site I have used this script I cant get the email address that is entered to show in Outlook as the place it came from and the subject doesnt show either

    Can someone please help me.

    Thanks
    Failure happens, its what you learn from it that is important!

  2. #2
    SitePoint Evangelist OwainGDWilliams's Avatar
    Join Date
    Aug 2005
    Location
    Scotland, UK
    Posts
    435
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it working!

    Found this website : http://www.apptools.com/phptools/forms/

    Works a treat!

    O.
    Failure happens, its what you learn from it that is important!


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
  •