Hi guys,

I am after some advice please.

On my site there is a page which enables the user to select a file from a dropdown box & click on download to either open or save the file which is working fine.

I have added an 'Email' submit button next to the download button so if the user wants to email the selected file from the dropdown box instead of opening or saving it I want Microsoft Outlook to open with the selected file as an attachment.

Any help on this would be greatly appreciated.

Thanks.
Lee.

    This cannot be done. There is no way to manipulate outlook from the browser in order to make it attach a file.

    Consider the alternatives - perhaps you could send the message with the file attached from the server using mail() or the other mail functions PHP has to offer.

      Ok. Thanks for the reply.

      However, I do know that Outlook can be opened using the simple 'mailto:' HTML tag so I thought with PHP being much more sophisticated it could be done using PHP.

      I'm very surprised.

      Thanks for the reply anyway.

        Ok so to get around this problem I want to give the user the option to email the selected file from the dropdown list to the email address which the user enters in a text field then clicks the 'Email' submit button.

        This is the script for my form: -

        <?php
        //if the form has been submitted, display result
        if (isset($result))
        {
        echo "<p>$result</p>";
        }
        ?>

        <form action="" method="post" enctype="multipart/form-data" name="filemanage" id="filemanage">
        <fieldset>
        <legend>Upload file section</legend>
        <table>

        <tr>
        <td>
        <label for="upload">Upload file:</label>
        <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" />
        <input type="file" name="upload" id="upload" />

          <input type="submit" name="Upload" id="Upload" value="Upload" />
         </td>
        </tr>

        </table>
        </fieldset>
        </form>

        <form action="" method="post" name="filemanage" id="filemanage">
        <fieldset>
        <legend>Download file section</legend>
        <table>
        <tr>
        <td>
        <label for="download">Download file:</label>
        <select name="download" id="download">
        <option value="">Select a file</option>
        <?php
        include('includes/dropdown_menu.inc.php');
        dropdown("$foldername");
        ?>

          </select>
        
          <input type="submit" name="Download" id="Download" value="Download" />
          <input type="text" name="email" id="email" />
          <input type="submit" name="Email" id="Email" value="Email" />
        
         </td>
        </tr>

        </table>
        </fieldset>
        </form>[/B]

        This is the include script which controls the download of the selected file: -

        <?php
        if (array_key_exists('Download', $POST))
        {
        $getfile = ($
        POST['download']);
        // define the pathname to the file
        $filepath = "$foldername".$getfile;
        $ext = substr($filepath, strrpos($filepath, '.')+1);
        switch ($ext)
        {
        case 'pdf':
        $type = 'application/pdf';
        break;

        case 'jpg':
        case 'jpeg':
          $type = 'image/jpeg';
          break;
        
        case 'xls':
          $type = 'application/vnd.ms-excel';
          break;
        
        case 'doc':
          $type = 'application/vnd.ms-word';
          break;

        }
        // check that it exists and is readable
        if (file_exists($filepath) && is_readable($filepath)) {
        // get the file's size and send the appropriate headers
        $size = filesize($filepath);
        header('Content-Type: '.$type);
        header('Content-Length: '.$size);
        header('Content-Disposition: attachment; filename=' .$getfile);
        header('Content-Transfer-Encoding: binary');
        // open the file in binary read-only mode
        $file = @ fopen($filepath, 'rb');
        if ($file) {
        // stream the file and exit the script when complete
        fpassthru($file);
        exit;
        }
        }
        }
        ?>[/B]

        What would I need to add to this script so that when the user enters an email address in the 'Email' field & clicks the 'Email' submit button it emails the selected file?

        I appreciate this is probably a tricky one but any help would be greatfully recieved.

          And just as a note:

          Lee W wrote:

          However, I do know that Outlook can be opened using the simple 'mailto:' HTML tag so I thought with PHP being much more sophisticated it could be done using PHP.

          Regardless of whether or not you're using PHP, it is the HTML and only the HTML that is interacting with the client (and therefore Outlook). PHP doesn't know what a hyperlink or a mail client is; it knows how to output whatever HTML you tell it to, however.

            Thanks guys for your replies.

            I will try to utilize the answers google offers & mark this as resolved.

            Thanks again.

              Write a Reply...