Can PHP offer accurate sent mail reports? - php

I´m using Drupal (PHP) and sometimes I use it to send email to some of my registered users (ie. using a contact form located inside their profile). This is very common in every CMS, PHP forum, etc.
The thing is that Drupal usually prints out a successful message when the email was sent, and not always the email is actually sent.
On the other hand, my hosting uses VHM panel with VPS servers.
From their control panel I can check all mail that goes from my server to the outside. In VHM it´s called "Mail Delivery Reports". That´s accurate enough, and I think most VPS control panel probably have some similar utility.
My question is: When Drupal tells me that the email has been sent, and I go to the Mail Delivery report on my hosting control panel, and it says that it has not been sent. Is that a PHP flaw?
Is there a way to get accurate reports within PHP?
Please excuse my grammar. It has been kinda difficult for me to actually get myself clear on what I mean in english.
UPDATE:
I´m not asking if the user reads the email, not even if it later on gets bounced, just to know if PHP has some accurate way to report if the email was sent.
I know there are some services offering that, but I´m just asking about PHP capabilities (and if that´s actually possible).

PHP responsibility is to give it to your specified transport method. (sendmail, smtp etc.) and tell you if the transport accepted it or not.
If you use sendmail (or postfix) what php tells you is that it has been queued for sending and nothing else. PHP doesn't know if it will be sent or not. unless you parse the queues and try to go from there.

No. It is impossible for PHP to track sent emails. That is not, never has been, and never will be, PHP's job.
PHP simply generates the email (e.g. builds the html) and then hands it over to a mail transfer agent. e.g. your local sendmail.
In a real-world equivalent, PHP is you walking an envelope down to the street corner and dropping it into the mailbox. If the letter disappears down the chute, PHP will report success. After that, actual DELIVERY of the mail is entirely out of PHP's hands.
Maybe the mailbox gets flattened by a drunk driver, maybe the pickup truck gets into a firey crash, maybe the postal sorting facility gets hit by a meteor, etc...
None of that is PHP's problem, and undetectable by PHP anyways. It walked down the street, it saw the letter disappear down the slots. Mission accomplished.
At best you could set the "return service requested" mail headers, which 99.99% of people will probably ignore or disallow, or embed a web-bug inside the email and hope that the recipient's mail client will actually load the bug.

Related

Service which presents your outgoing email as a draft email when testing on localhost?

Lots of answers here and elsewhere on Google for how to setup your WAMP or XAMP on localhost to send emails.
However for testing/developing, you mostly don't care about emails actually getting transmitted. You just want to check how they're formed, and whether the email picked up the correct settings and options.
So, I remember having this problem a few months ago and finding a solution/service which did this:
As soon as my PHP code triggered an outgoing email, it would present it as a real draft email in a new window in my email client (Outlook, as it happens). I could check the from/to/subject/body instantly and easily. Nothing actually got transmitted, and I didn't have to keep a bunch of inboxes open somewhere or worry about delays or junk folders.
Trouble is I can't remember how I set this thing up. It was either a service which I downloaded and installed or it was a tutorial on how to set this up in WAMP. It was possibly a WordPress plugin but I'm not sure. I am certain it was free.
Does anyone recognise this kind of setup for email testing in PHP?
Are you sure it is a PHP configuration and not a software?
I used a mail smtp 'catcher' that works as you describe.
I hope it could be useful for your interests: Test Mail Server Tool (http://www.toolheap.com/test-mail-server-tool/)
I'll be accepting Nacho's answer. For completeness ... following StackOverflow's Related questions and checking out some other answers, I see there's also a service called Papercut mentioned here, which I might also check out.

php mail() often not reaching the address

this is my problem, essentially - I set up a wordpress contact.php template that would submit forms and send it to my gmail. However, the issue is that it reaches the email only less than half of the time, and it's imperative that I get the rest of the emails.
The next issue related to this is that I did not set up a file that would log the sent out messages. MY question is, basically, - is it possible in any way to retrieve the sent emails that haven't been logged? is there usually a cache of emails maintained by the hosting provider? The only information I have is the IP addresses, and that is hardly any help in this situation.
Thank you.
Probably being hit by your spam filter. PHP's mail() function is prone to this because the mail is sent from the web server, which isn't generally configured with SPL, etc, that receiving mail systems look for to help them filter out spam.
I don't think I can answer the question of how to retrieve lost messages that have already been sent -- only your hosting provider can really help you with that, but my guess would be that they can't help. They are very unlikely to keep hold of outbound emails any longer than necessary. If you're lucky, they might have logs of email events, but even that might not have any useful data in it for you.
One question though: Have you checked your gmail spam box? I'm not a gmail user, but most mail systems do keep a spam box with filtered messages, so that users can retrieve an email that gets marked as spam incorrectly. I'd be surprised if gmail doesn't allow that, and if that's where your mail has gone, then problem solved.
For the future, I suggest switching to use a decent third party library for your mail such as phpMailer.
The advantage of phpMailer for you in particular is that it can be configured to send mail via gmail, which means you can send it to yourself from own account. This should be pretty much bullet proof as far as spam filtering is concerned. It should also be delivered quicker, since the mail will go direct to Google's servers, without needing to bounce around the internet first.
phpMailer will also make your mail code much cleaner than using the raw mail() function, and it allows more advanced features like attachments, without having to write mountains of code.
Hope that helps.

PHP mail / PEAR mail

On my directory website I have a "send email" functionality. This lets a user submit an enquiry to a company. A copy of this enquiry is also sent to my inbox.
A few months ago I noticed that I had stopped receiving the email copy to my inbox. So I investigated this and it turned out that my web host was no longer allowing sending external emails using the PHP mail function.
When I questioned this I was told that I would need to start using a third party mail plugin, and I was recommended to use PEAR.
So I converted my PHP script to use PEAR and managed to get it working on my site. All was good until until one day I thought it would be a good idead to switch to PHP 5.3 on my web host. A few days later I noticed that I had again stopped receiving the email copy to my inbox.
So again I investigated this and found that it was broken. I was told that I would need to revert back to PHP 5.2 for this to work. So basically that's what I had to do to make it work again.
My question is, how can I know when the mail functionality is broken as soon as it breaks? During the time it takes for me to realise it's broken, several enquiries could be being sent from the site which aren't actually going anywhere.
And secondly should I stick with PEAR or are there any better alternatives out there?
There are a number of alternatives to PEAR::Mail. However first I have to address the question of whether your goal is to pay your hosting company so that they arbitrarily break your site and subsequently, your business? I'm not sure why anyone would pay to be on a habitrail wheel of fail, and pay for that.
With that said this package http://swiftmailer.org/ has become very popular and is bundled as part of the symfony2 framework, which is an excellent endorsement of its functionality and support for the latest/greatest features in PHP.
Prior to that, http://phpmailer.worxware.com/ was a very popular package.
As for detecting whether your mail is working, the only way to do that is to have an automated test job that sends you an email every day, or at whatever periodicity you want. If you don't get that email, you know that there is an issue that requires investigation.

Sending mails via php and it reflects in the owners sent items

When sending a email via php i want it to appear in my outlooks sent items.
I have tried imap_send but it does not reflect in the sent items. Is this possible. Thanks
edit
i used imap_append to solve achieve this.
imap_append($connection, "{mail.example.com/novalidate-cert}INBOX.Sent")
The only way that I know for 100% sure this is possible is by sending through an Exchange account. That way, Exchange will sync the sent items folder on an Outlook client.
If your PHP instance is on the same machine as the Outlook instance, this may be what you're looking for - although I haven't tried it so I don't know if it works.
If your PHP instance is not on the same machine as Outlook and you don't use Exchange, you're scuppered.
EDIT
It may be possible to do this with IMAP, as long as you configure Outlook correctly, but it would also depend on the mail server keeping a local sent items folder and handling mail sent through it correctly, which it may not.

Fast email delivery

I have a website that receives incoming emails via cloudmailin, adds the content to the database, and then sends a confirmation email back to the person who sent the email. Currently I'm using a php mail() function to send the reply, but it seems to take about 1.5 min to actually get to the user's inbox. Is there a way to make this more instantaneous? I'm currenly hosting the application on FatCow, and I'm sure it has to do with their mail server, but I don't really know much about how that works and am wondering if I have to change hosts to accomplish faster delivery times or if I can do anything about it without switching.
mail() is a black box. You're telling PHP to try sending a mail however the host has configured PHP to do so.
It's very likely that it's just calling sendmail in your case. It's also very likely that the mail queue on that machine isn't the fastest in the world. Shared hosting machines are often overloaded.
The very first thing you should do is ask your host about the mail delay. Perhaps something is wrong, and they can fix it. Or they might just tell you that a minute and a half is not a long time to wait.
There are lots of other options, mostly in the form of companies that provide an SMTP service to you. I can't recommend one, but I can recommend that you pop over to your favorite search engine and look for "smtp service." I've recently starting working with Amazon Simple Email Service. It's supposed to be fast and well-maintained, and it's certainly inexpensive.
All of those options are likely going to require some configuration changes on your end. For example, you'll want to set up custom DNS records (for DKIM and SPF) to ensure that mail from a third party provider isn't automatically flagged as spam.
Using SMTP with PHP is dead easy. There are plenty of mail generating options out there. My personal favorite is SwiftMailer. It even has a transport option for Amazon SES.
The final option, of course, is grabbing your own virtual private server or dedicated server, which will let you configure outgoing mail as you desire, at the cost of needing to know how to maintain that server.
Edit: Obligatory link to relevant Coding Horror post.

Categories