i'm new in php. I want to send an email to someone and afterwards i need to check if this mail could be received. How do i do that? Hope you guys understand my problem ;).
Thanks in advance. Marc
That's a really sticky question. The only real way is to have PHP monitor an inbox to check for "undeliverable message" notices you might get back. If you're really wanting to go forward with it, look into POP3 connectors for PHP. Like this: http://pecl.php.net/package/POP3
if (strpos(strtolower($subject), 'undeliverable') !== false){
//do whatever you want with the address that couldn't be reached
}
You technically wouldn't need a compiled PHP extension for POP3 (especially if you're new to PHP)... you could connect and read messages by opening a socket and speaking mail server:
http://www.adamsinfo.com/a-rudimentary-php-pop3-example/
Edit (years later):
Definitely check out http://mailgun.net/, http://sendgrid.com/, and http://postmarkapp.com/.
If you're sending HTML mails, you could use a little trick:
generate a unique id for the mail you are sending (based on content and recipient)
include an image that is loaded from your webserver
<img src="http://yourdomain.com/tracker.php?id=1234567" />
in tracker.php, log the id that called the script and send a 1px by 1px image
This won't work though, if the mail client does not download images from the internet when showing an email, as Thunderbird does, for example (IIRC Outlook does so too)
There is no definite solution for this. Web bugs are a o.k. idea but they're dying out, as they are very problematic security wise and are blocked by default in every current E-mail client I know of. I would suggest a combination of checking a bounce inbox like brianreavis suggested, and in addition, requesting a delivery receipt using the following header line:
Disposition-Notification-To:<xxx.xxx#example.com>
That way, you can get most negatives (bounced mails) as well as many positives (receipts). Sending the receipt can be blocked by the sender, but together with parsing error notifications, you should have fairly reliable system.
One option is a Web Bug but these are far from 100% reliable, and are arguably not a nice way to behave. It won't differentiate between emails which are unread and those which are undelivered, for example because of a bad email address, and it is possible to read an email containing a Web Bug without triggering it.
In short you create an HTML email containing an element which has a URL on your site which is unique to that email. So if a client accesses that URL you can be sure that someone has read your email. Wikipedia gives this example:
For example, an e-mail sent to the address somebody#example.org can contain the embedded image of URL http://example.com/bug.gif?somebody#example.org. Whenever the user reads the e-mail, the image at this URL is requested. The part of the URL after the question mark is ignored by the server for the purpose of determining which file to send, but the complete URL is stored in the server's log file. As a result, the file bug.gif is sent and shown in the e-mail reader; at the same time, the server stores the fact that the particular e-mail sent to somebody#example.org has been read.
However, it is possible - probably quite likely - that someone can read your email without connecting to that URL. This may because:
A lot of email readers block such links by default because of privacy concerns precisely because of Web Bugs like this.
They read the email in text only, either because their email client is configured to do so or because it can't display HTML email, for example, a lot of mobile phone clients.
This is a often used option - both by spammers and more responsible marketers - but I probably wouldn't recommend it unless you fully understand its limitations and implications in terms of what people might think of you if you do use it.
There is a perfect solution, in terms of knowing the eMail has been read.
The bad part is that the body of the eMail must be stored on web server.
The trick:
-Send an eMail just just a small text and a URL, so the user must go to that URL to read de content of the eMail.
In other words... on the eMail there is nothing about what you want to send, there is only a link to a unique page you create before sending such eMail.
So to read the content the user must open a web browser and go to such URL.
The trick is to put a little of such text on eMail... something like: bla, bla, bla ... press here to read more.
The concept: Online body, offline URL to access such body.
That way you can be sure of this: if URL has been read, the eMail has been read.
The bad part is that the info you want to send is not on the eMail, must be on a unique webpage.
So you must control no robot can go to such URL... for example with URL like:
https://server/private/?eMail_Body=user
Hope this idea can help someone.
Related
I am trying to work out how to do something. It must be possible - I've seen something similar done in multiple systems (Twitter, facebook etc.)
The basic thing I want to do is - someone leaves a comment on my website. The comment goes to my email, as well as to my MySql database. I then reply directly on my email. The reply is saved to the database, and auto-approves the user's comment.
I can't work out how to speak to my MySql / PHP system directly from an email. Also - I can't work out how to set up the inboxes?
I am guessing that I'd need to set up mailserver rules so that emails sent to xxxx-response#mydomain.com are actually redirected to a php script, where xxxx is an identifier of the original comment?
Thanks for any light that you can shed...
Assuming you're on a unix system, you could set up an account for receiving the mail, e.g. "fred", and use a .forward in fred's home directory to pipe emails to your php script. e.g.
.forward:
|"/usr/bin/php /path/to/your/script.php"
which will invoke your script anytime an email arrives in fred's mailbox.
You can't 'talk to mysql from an email'. An email is a passive piece of text, nothing that can take actions.
The solution is based on something like this:
You have an email account and poll that accounts Inbox by a php script in a periodical manner, by using wget or similar in combinition with a crontab entry. You can also create an event driven approach, but that is more complex and does not really offer advantages. For all messages found inside that inbox you check if it matches any previous entry in the database. You can do that since you have access to the messages headers and body (the text) by php. That is all you need. Typically the connection between two messages is done by evaluating the 'In-reply-to' header that is set by email programs when you press the reply button. It is like a reference.
The access to the accounts inbox is done by standard mail access protocols, typically pop3 or better imap4. When the mail server is not on the same system then abviously you want to add ssl encryption too. php's imap extension is a very good start for implementing such a client, it supports several protocols.
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
I've written an email application in PHP that handles very large mailing lists. Is there a way to find out what emails are opened and by who? Any solution will do as long as it can tell me if the user has actually received and opened the email. I do not want to use email receipts either as it may put off recipients.
If it's relevant, I'm using the codeIgniter framework.
You can accomplish this by including a small tracking image in every email that is sent out.
<img src="http://yourdomain.com/tracking/1x1.gif?cId=12345&uId=56789">
Use mod-rewrite to push everything beyond '/tracking/' into your analytics script, snag the query_string and return a 1x1 gif to the email clients.
From Campaign Monitor:
http://help.campaignmonitor.com/topic.aspx?t=89
When each email is sent out, we
automatically add a piece of code that
requests a tiny, invisible image from
our web servers. So when a reader
opens the email, the image is
downloaded, and we can record that
download as an open for that specific
email.
It is important to understand that the
open rate is not a 100% accurate
measure. Recording an 'open' can only
happen if the reader's email client is
capable of displaying html with
images, and that option is turned on.
So if you are sending text-only
emails, there is no way to record open
rates. Similarly, people reading your
html email without images showing will
not be recorded as opens (unless they
click a link).
Another issue is that your readers may
have a preview pane in their email
client. That preview pane might be
displaying your email automatically
(and therefore downloading the images)
without the reader ever having to
click on it or read it.
So you should never take your open
rate as a hard and fast number,
because you can never know the true
figure. It is much better used as
general guide, and as a way of
measuring the trends on your email
campaigns.
You can put a tiny invisible img in each email, each image named differently to corespond with a specific email. Then you parse your access logs and see which images have been requested and you know which emails have been opened.
It's not fool proof but i've seen some companies use this method.
There's read receipts, but those are only supported by specific clients (ie, Outlook), and even then they are given the option to not notify you of their reading it.
The only other option is to communicate with your server when they read the email. To do this, you can implement a tracking pixel, which is a 1x1 transparent gif. You can intercept the response on your server and log the time, date, ip address, etc.
This still isn't foolproof though, because some clients such as gmail don't show images by default.
You can read more here: http://en.wikipedia.org/wiki/E-mail_tracking
once we send email from php using mail() function, is there any way to check either mail is open or not?
may be any type of database insertion code in email..?
or calling any function from website?
any possibility.........
i search on internet all the day but did't found any ans.
Thanks
Small images - called Web Bugs - are the only direct way as Szere Dyeri points out, but they are increasingly frowned upon and blocked by every major mail client for privacy reasons now. I would not consider them a reliable way to tell whether an E-Mail has been read any more.
There is a legitimate way to request a read receipt by adding the following header to the E-Mail:
Disposition-Notification-To: your#address.com
Sending of this notification can be turned off by the recipient of course.
Add an invisible small sized image to the email content. And, let the image point to a unique url on your website. You will know that email is opened once that url is accessed. But this will not work in email clients that does not show images in the emails by default.
I found this web service called Get Notify. They claim they do this for free but you need to verify for yourself.
The only way to do this would be to include an image in the email that resided on your server which includes a key to match to the user you are sending the email to. For example, I send an email to Joe#mail.com. In my database (or other storage system) I have Joe#mail.com matched to key 0100. In his email I include an image, like
<img src="http://www.myserver.com/image/?key=0100" />
On your server, /image/ needs to return an image, even a 1 pixel .png. Now you have the key that the user was assigned and can act accordingly.
Many people responded that adding a "tracking image" is a "frowned upon" method and 'considered "questionable" activity'.
Out of curiosity lets say we didn't include a separate tracking image but rather we included this method in an existing image like for instance added it onto your companies logo image like:
http://mycompany.com/images/logo.png?track=2742'>
At least with this method your tracking image won't get blocked by any scanning applications.
One legitimate way to do this is to only send textual information in the email asking the user to follow a link which you can then track. Something along the lines of:
//lots of good info to identify yourself/company
Thank you for your request...
Please follow this link: http://somewhere/ for tracking information
Unfortunately this leaves it in the users hands to acknowledge your request. This is considered to be the most respectful way to do it.
If your application is not public facing (i.e. an internal app for your company), then the img src method already posted is a good technique.
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");