Search code examples
phphtmlmailto

mailto: unable to add attachments


I have an HTML link. I'm using mailto to open up the mail when a user clicks on the link. I'm able to set the to email id and subject but I'm not able to add an attachment.

This particular form is now in localhost but it will be moved to live server later. These attachment files are stored in a folder and I get the path to these files from a PHP variable.

I tried passing the path to it but it didn't add the attachment.

How can I make this happen?

Here's the sample code.

$filePath = 'C:\xampp\htdocs\sampleProject\attachments\pdfs\samplepdf-03.pdf'

<a href="mailto:?subject=Pictures from PhotoAlbum
         &body=This is the body text
         &attachment='<?php echo $filePath; ?>'">
Email This
</a>

Solution

  • You can't. The mailto: URI scheme doesn't support attachments (and the client wouldn't usually have access to the web server's hard disk anyway).

    Consider sending the email from your PHP instead of from your visitor's email client.