In this second part of a two-part article, you'll learn how to manage email headers when creating a PHP email program, attach a file to a message, and more. This article is excerpted from chapter eight of the Zend PHP Certification Study Guide, written by Zend Technlogies (Sams; ISBN: 0672327090).
mail() returns TRUE if the email is accepted for delivery. This does not guarantee that the email will be delivered.
Internet email is an unguaranteed delivery system.
Email messages can be lost at any point between your MTA and your user's MUA. This is often caused by a catastrophic disk failure on an MTA, combined with inadequate backups. When email messages are lost, there is no automatic mechanism to trigger re-sending the email message. Lost email messages are never delivered to the intended recipient.
A more common problem is email messages that get rejected by the user's MTA. Causes include
Inbox over quota
Email too large to accept
Disabled user account
Misspelled email address name
Virus scanner detected a virus in an attachment
When an MTA rejects an email message, it normally sends back the email message with a description of why the email was rejected. These 'bounced' email messages are never delivered to the intended recipient.
If the email message is successfully delivered to the intended recipient, this can still cause problems. The user might use a filter that bounces email from senders not in a whitelist. The user might have set up a vacation auto-responder, which automatically sends back a message saying that the user is currently out of the office.
It's therefore essential that your PHP application can cope with these situations:
Every single email you send should have a valid Reply-To: header, to allow receipt of bounced email messages. You should set up a mailbox just for bounces to emails sent from your PHP scripts. It's a good idea to have someone go through the mailbox once a day, just in case there is anything you can do about the bounced email.
Normally, there should be a way for the user of your PHP script to make your script send the email again.
Any order confirmations, receipts, and invoices that you send via email should also be available through some other means—either via your website, or via snail mail. Apart from being good customer service, many of these documents are legally important.