PHP mail attachments

Discussion in 'PHP' started by Weirfire, Dec 5, 2005.

  1. #1
    I've been trying to use the attachment scripts at http://uk2.php.net/mail to email msword files that have been uploaded to the server and I can't for the life of me get the attachment script to work.

    Has anyone managed to get a PHP mail script to work that attaches files or more specifically msword files?
     
    Weirfire, Dec 5, 2005 IP
  2. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have the same question going, What i have ended up doing is 2 forms, a simple script for a form and then if they want to send documents, a simple script for uploads.

    The script for uploading is like this, simple htm

    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Send Your File" />
    </form>
    PHP:
    and on the other page

    <?php 
    // Where the file is going to be placed
    $target_path = "uploads/";
    
    /* Add the original filename to our target path. Result is "uploads/filename.extension" */
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    
    // This is how we will get the temporary file...
    $_FILES['uploadedfile']['tmp_name'];
    
    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been sent to me, and will appear on the website soon. <a href='index.php'>Click here</a> to go back to the home page, or <a href='send_your_stuff.php'>click here</a> to send more stuff<br><br> If you have any problems, please email me at <a href='mailto:jokes@onlyican.com'>jokes@onlyican.com</a>";
    
    } else{
        echo "There was an error uploading the file, please <a href='send_your_stuff.php'>click here</a> to go back and try again or email me the file at <a href='mailto:jokes@onlyican.com'>jokes@onlyican.com</a>";
    }
    ?>
    PHP:
    You also need to change the folder setting to 777, which you should be able to do with your ftp program, if you find a way to have the form sent and the document sent in one form, please post here or email me at
     
    onlyican.com, Dec 5, 2005 IP
  3. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #3
    Nah this is a different question.

    I have managed to upload my files to the server ok through the html form but I want to use the

    mail("example@domain.com", $subject, $message, $headers);

    function to actually send the uploaded file to an email address.
     
    Weirfire, Dec 5, 2005 IP
  4. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thats what i wanted. I wanted someone to comeplete a form, name ect, with an option for a file, then when they send the form, i would get an email with the details the completed and the file, jpg, mov, pps ect.

    I could not find this, I don't know much php, but hey, next month is a new, year.
     
    onlyican.com, Dec 5, 2005 IP
  5. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #5
    Weirfire, Dec 5, 2005 IP
  6. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #6
    phpmailer is definitely the way to go :)
     
    Weirfire, Dec 5, 2005 IP
  7. onlyican.com

    onlyican.com Peon

    Messages:
    206
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I tell you a really good find, if you want files uploaded, with little work, then a good directory lister is located at http://evoluted.net/
     
    onlyican.com, Dec 5, 2005 IP
  8. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #8
    uploading files isn't a problem. Due to some server settings I had to figure out 3 ways of uploading files lol

    I have a question for the PHP gurus though;

    Which method is better for uploading files

    copy() or move_uploaded_files() ?

    I found copy() the cleanest looking but perhaps it's not the best performance method.
     
    Weirfire, Dec 5, 2005 IP
  9. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    The move_uploaded_file() only handles the files that is uploaded to the server. You can use copy() on every file on the system.
     
    hnn, Dec 10, 2005 IP
  10. Weirfire

    Weirfire Language Translation Company

    Messages:
    6,979
    Likes Received:
    365
    Best Answers:
    0
    Trophy Points:
    280
    #10
    So would you normally use copy() or do you use move_uploaded_files as well?
     
    Weirfire, Dec 10, 2005 IP
  11. hnn

    hnn Peon

    Messages:
    91
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I normally use move_uploaded_file() when i handle uploaded files, because of the error handling, and copy() the other times.
     
    hnn, Dec 10, 2005 IP