www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] PHPMailer with Multiple Attachment

  1. #1
    Join Date
    Mar 2013
    Posts
    18

    resolved [RESOLVED] PHPMailer with Multiple Attachment

    I am trying to create a webform that has 4 upload field. I want to have the uploaded file email to me with phpmailer. I need to know how to validate that the uploaded files are images, attached via phpmailer and send to an email address. I found the below code that will move the file to a folder but I want to attached the files to email without moving them. Is that possible and how do I do it? Any help will be much appreciated.

    PHP Code:
    $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 uploaded";
    } else{
        echo 
    "There was an error uploading the file, please try again!";
    }
    $mail->AddAttachment($target_path); 

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    PHP Code:
    $mail->AddAttachment($_FILES['uploadedfile']['tmp_name']); 
    Best way I know of to verify a file is an image is to find out if getimagesize() returns a non-empty array.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2013
    Posts
    18
    Thanks NogDog. Can you please provide an example of how to use getimagesize() function? Also, do I just use the $mail->AddAttachment, is that mean I don't need to do the coding I have posted? thanks for your help.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,144
    PHP Code:
    if(getimagesize($_FILES['uploadedfile']['tmp_name']) == false) {
      
    // it's not an image (or at least any type PHP recognizes)

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles