Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    2,469
    Thanks
    0
    Thanked 0 Times in 0 Posts

    POST files through a mail form using PHP

    I've attempted to add to my php form (created with codingforums support ) to email files -- this is for people to send us their resume and coverletter -- by using the PHP method:
    http://us4.php.net/manual/en/features.file-upload.php

    However, this uploads to a server, not necessarily sending to an email. Can this be done? If so, what variables can I use to add this to my code?

    The html file inputs are basic enough:
    Code:
    <input type="hidden" name="MAX_FILE_SIZE" value="50000" /> 
    <input name="coverletter" type="file" size="15" />
    <input name="resume" type="file" size="15" />
    And the full php form is pretty straight forward:
    PHP Code:
    <?php 
    $first_name
    $_POST['first_name']; 
    $last_name$_POST['last_name']; 
    $title$_POST['title']; 
    $company$_POST['company']; 
    $address1$_POST['address1']; 
    $address2$_POST['address2']; 
    $city$_POST['city']; 
    $state$_POST['state']; 
    $zip$_POST['zip']; 
    $country$_POST['country']; 
    $email$_POST['email']; 
    $phone$_POST['phone']; 
    $fax$_POST['fax']; 
    $category$_POST['category']; 
    $request_category$_POST['request_category']; 
    $request$_POST['request']; 
    $message=  $_POST['message']; 

    $body 
    First Name: $first_name 
    Last Name: $last_name 
    Title: $title 
    Company: $company 
    Address: 
        $address1 
        $address2 
        $city 
        $state 
        $zip 
        $country 

    Email: $email 
    Phone: $phone 
    Fax: $fax 
    Request Category: $request_category 
    Additional Info: $request
    $message 
    "


    if  (!isset(
    $email)  ||  !isset($first_name))  { 
    header("Location: [url]http://www.academystudios.com/error.php[/url] "); 

    elseif  (empty(
    $email)  ||  empty($first_name))  { 
    header("Location: [url]http://www.academystudios.com/error.php[/url] "); 

    else  { 
    mail("sales@academystudios.com","From: academystudios.com visitor",$body); 
    header("Location: [url]http://www.academystudios.com/thankyou.php[/url] "); 

    ?>
    Any ideas how to adjust, if I can even accomplish it? I'm trying to keep away from CGI, i've been successful at that for years now
    // Art is what you can get away with. <-- Andy Warhol
    ...:.:::: bradyjfrey.com : htmldog : ::::.:...

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes you can accomplish this!

    I just checked out the php manual:
    http://www.php.net/manual/en/ref.mail.php

    Search for the following user comment:
    nico at cpp-club dot net
    30-Jan-2004 03:33

    And you'll have your answer!

    Basically you use the file upload method you posted and upload the file into a directory on the server. Then you use nico's method to send the message. You store the resume and coverletter in the attachment array.

    Read the first user comment about magic_quotes.. it may save you some grief in the future..

    Hope that helps,
    Sadiq.

  • #3
    Senior Coder
    Join Date
    Apr 2003
    Location
    San Francisco, CA
    Posts
    2,469
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There is no other way to do it without saving it to my server AND then emailing it off? Why not a direct send?
    // Art is what you can get away with. <-- Andy Warhol
    ...:.:::: bradyjfrey.com : htmldog : ::::.:...

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Short answer:
    Because you can't.

    Long answer:
    Let's break it down. Who's sending the email? The server or the client? If your 'action' in the form tag does not begin with mailto: then it's the server sending the email.

    Let's pretend you're the server. You want to send an email. You type it all up and now you want to attach a file to the email. But that file is not on your computer. How are you going to attach it? If it's on the web, you can include a link to it, but that's not the same as an attachment, as the reader will have to click on the link and then save it to their harddrive. But in your case, the file is not on the web.

    Does that make more sense?

    I assume you're having an issue with uploading the file because of server space. Well once the file gets uploaded, it will be stored in a temporary file by default. Usually you would need to move that temporary file someplace, but in this case you don't need to. You just attach that temporary file to the email and you're done.

    I'm not sure how you clear those temporary files, but I assume that gets taken care of on its own.

    If you have any further questions, or if anyone wants to correct me, just post.

    Hope that helps,
    Sadiq.


  •  

    Posting Permissions

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