Search code examples
javascriptphpemailjoomla

Select file stored on web server and send as attachment in email?


I was hoping someone could help me/guide me in the right direction with this issue.

I want to create a button called "Send File". When this button is clicked, a directory on my web server is opened where multiple PDF files are stored. I must then have the option of selecting multiple files. Once I click "Okay/Confirm", a new mail must be opened on Outlook with the files added as attachments.

So it's basically like adding an attachment on your local computer through Outlook, but the only difference is the "source" of the file is in a directory on my web server.

I hope this question isn't too broad or not specific enough. I have really no idea how to go about this, so any tips are appreciated. I will attempt to write some code but I don't have a clue on how I'd do this.


Solution

  • Here is a quick example:

    print_r($_POST['fileName']);
    
    $array = array(
    
      'file1.pdf',
      'file2.pdf',
      'file3.pdf',
      'file4.pdf',
      'file5.pdf',
      'file6.pdf',
      'file7.pdf',
      'file8.pdf',
    
    );
    
    echo '<form action="" method="post">';
    
    foreach($array as $file){
    
       echo $file . '<input name="fileName[]" type="checkbox" value="' . $file . '"><br>';
    
    }
    
    echo '<input name="submit" type="submit" value="Submit">';
    
    echo '</form>';