How do i add an attachment to an email? - php

This may seem like an easy question, but --
How do i make it so when a user clicks on a link on my site, it opens up an outlook (or whatever client they use) with the file (in the link) as an attachment?
I don't want to use php's mail() function since i want the user to be able to send it as an attachment him or herself.
Or is this whole thing impossible?
Thanks.

That's not possible. At most you can set the To: and Subject: lines via the link itself, but you can't force an attachment.
Click me!

Sorry, you can't do this. The best you could do is mailto link which unfortunately doesn't allow to set attachments.

You can create a form field for the user to enter his / her e-mail, then post to a php file which will grab that e-mail addr and send your attachment.
besides - mailto links are a pain in the A$$ for some users because they may be using a web based e-mail client as their primary, and a mailto will force something like outlook to open

Related

How can i know if an attachment has been downloaded from mail?

Recently I came to know that for mails we can,
1. Track Click-Throughs
2. Track Opens
Read more from this blog You Know How I Know You Read My Email?
Now I need to know how I could know whether someone downloaded the attachments in the emails.
Is this possible?
Thanks
Attachments are part of the email, so most clients will download it with the email (e.g. desktop clients, etc).
If you want to send a file and track whether it's been downloaded, then you'll have to host it online somewhere, and email the link. When the recipient clicks the link, the website where the file is stored can track when the link has been accessed and thus tell you the file was downloaded.
In general, you can't.
The attachment is embedded in the email. There is no way to track what happens to it afterwards unless the attachment has something in it that will allow you to track opens (such as a reference to an external image in an attached HTML document).
I don't think Its possible to trace attachment download.
Only you can trace you'r email checked or not by the receiver.
Via sending the small image in to the email and call you php file path.

How to generate a temporary email for use in a web-application?

Example: if I want to upload a video to some video service website (such as Youtube) by email, I can send a video to an email address (e.g 1234567890#upload.youtube.com). The number is an upload code - It's a unique number and changes every time. Then Youtube will process and upload my video automatically.
How did they create the email address 1234567890#upload.youtube.com, and how did they process an email message that a user has submitted?
I'm looking for the basic functionality behind this kind of web-application.
I've never done this, but I have a basic idea of how this is done.
There's a mail server on upload.youtube.com waiting for any email no matter who's the recipient.
Once it gets a message it will pipe it to a script which can parse it and get the recipient address (that's the uploader's unique identifier).
Then it will look in the email for the attachment and get MIME code, base64-decode it and then write it to a file on a disk.
Then it will add an entry in the database with the user's unique identifier and the link to that uploaded content.
if you use cPanel you could use something like http://www.zubrag.com/scripts/cpanel-create-email-account.php to create the email accounts (use your own routines to generate the unique username etc) then you could use a script like http://garrettstjohn.com/entry/extracting-attachments-from-emails-with-php/ to get the attachments from the email.
Finally, I figured out what I want.
All I have to do is handle with catch-all email on my web control panel. In my case, I just create a new subdomain and set a catch-all email option on that subdomain.
You can do all of above in Cpanel easily - just create a subdomain and selected a radio box Pipe to a Program and fill your application path. That's it!
Unfortunately, I'm using DirectAdmin. I have to do more complicated than Cpanel. It can handle with catch-all email as well, but I have to use wildcard dns for my subdomain record first.
In addition, I found this useful article about how to Pipe / Send Email to PHP Script. This article will show you every step including a PHP script for using with email piping.
Thank you for all answer. It's very helpful.
That's nice to know that you have achieved this.
I am here to introduce you to a script that can help you. The script is dealing with the dynamic email addresses with PHP. You can see the script at github and there is a premium version of this software you can see a demo here. You can buy the script from codecanyon.

PHP / HTML to be able to forward Outlook email?

I'm building a newsletter with PHP (Zend) / HTML / CSS, however I've added a "share" button on the newsletter design, I'm wondering if it's possible to somehow integrate it so that whenever someone clicks in this button, the forward outlook functionality would occur.
Is this possible? can someone point me out to the right direction?
You could link to mailto:?subject=<subject>&body=<body>, but it means that the entire content of the subject and body should existing in an url-encoded fashion inside that link. This means that the e-mail will be twice the size. Also, when you embed pictures, those will not exist in the new e-mail, so you will need to link them from the web.
And then, it's still fake. You can't really forward from inside the e-mail, it's just a trick that may not work very well, depending on the client. Especially when the mail is opened in a webmail page. A click on the link will start the offline client, or maybe no client at all, if the user hasn't got one.
Long story short: You can't, you shouldn't.
Trust your user that they know how to find the forward button, or redirect them to a site where they can enter addresses to forward too.
No email client that i know of support this feature in any way. Not even a reply possible. Maybe what makes you think this could be possible is the mailto: anchor handler that only asks the system to start an email edition with the ?subject= and body= query parameter.
But it doesn't allow you to edit or pass in any data to the mail client.
If you are going to be creating an HTML formatted email, you could simply include a mailto: link with a subject and body like so:
<img src="share_button.gif" alt="Share this" />
This would open a new email message in the users client of choice to allow you to send the email along. You could go as far as to include the html of the existing email in the body parameter. Keep in mind that it would need to be escaped html in order to display properly.
A better solution, IMHO, would be to take the user to a page on your site to enter an email address into a form which could then automatically send a copy of the email from your system.
why not just have the server send the email?
http://php.net/manual/en/function.mail.php
just beware of email injection vulnerabilities
http://en.wikipedia.org/wiki/E-mail_injection

Link to open email client and attach file?

Not sure if this relates more to PHP or Javascript/jQuery, but is there a way to attach a file to an email client (i.e Outlook), when user click on a link/button?
I have a link that generates a PDF and I want it so that, when someone click on a link, it will open up their email client with the PDF already attached, and subject already fill in.
I know, you can use <a href="mailto:..." but that only opens up the mail client. I also need to attach a file with a subject fill in.
Is this doable with PHP or Javascript?
You can set the subject line in the mailto with
MAIL TO EXAMPLE
setting an attachment is not that easy and you would be better off providing people with a button that will trigger php to send the email (as per ott's comment).
In theory some email clients will support adding "attachment=path/to/file.txt" attribute but I have never seen it work

PHPMailer: sending email....ask for a receipt?

I am going to create a script that sends out an email. I am currently using PHPMailer. I have been told that they would like the email to request a receipt from the user indicating they read it. (like what you often see in outlook). I have no clue if this is possible. Can anyone tell me if this is possible and if so how to do it?
Thanks!!
See $ConfirmReadingTo in PHPMailer documentation
( More recent PHPMailer link on gitHub )
I'm not sure if you can use them in PHP or not a quick search showed this:
Disposition-Notification-To: you#yourdomain.com
however they are not reliable in any way as most email clients either ignore them or just allow the user to hit 'cancel' to sending a reply. I've only really seen it used in corporate/enterprise type env with Notes or Outlook.
Just something to consider, but depends on your application.
In PHPMailer you use $ConfirmReadingTo. You need to set it equal to the email address you want the confirmation sent to. Ex:
$ConfirmReadingTo: you#yourdomain.com
But some email clients (such as gmail) will just ignore this.
The best way to get a confirm from every email sent would be to send an HTML email and use a graphic to track which emails have been opened. The graphic source would be a script which you would let you check who has read the email. Ex:
<img src="http://www.yourSite.com/emailConfirm.php?FROM=someone#gmail.com&SUBJECT=The_Email_Subject" border="0" height="1" width="1">
emailConfirm.php could then generate an email to be sent to your email address.
You can use Josh’s recommendation with tracking image, but:
- use a special folder name and custom image name with .GIF extension
- track this image request by php handler, as an exception by accessing this non existing image
- generate this custom image name into the email
For example:
<img src="http://www.yourdomain.com/email/abc34642.gif">
Your php exception handler detects, that you are requesting a gif image in the folder "email", which means, someone opened your email with the identification 34642. You have to find, which recepient has this id, and you can find the neccessary information. I recommend using a generated xml file to avoid too much database queries. Don’t forget to output a real image with gif header.
This is absolutely safe against blocking your email with inappropriate image extension.
I confirm as of today the correct method is doing:
$mail->addCustomHeader("Disposition-Notification-To: youremail#mail.com");

Categories