Re: mail() problems

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim,

I’m not an e-mail expert, but there’s nothing inherently wrong with the mail() function. Basically, all it does is hand off the message to whatever mail server is specified in the php.ini file. In most cases, at least on *nix servers, that means dropping it into the local sendmail queue. If it meets your needs, keep using it. If that’s the case, it’s better than using an overly complicated wrapper that will probably end up just using the mail() function, anyway. We routinely send thousands of messages a day using mail() without any problems whatsoever, running under PHP versions ranging from 5.1.4 to the latest 5.5.

There are a few things that can cause mail to periodically fail, however:

* Some mail servers really want a from: and/or reply-to: header, neither of which is usually set by mail() by default.

* Anti-spam software or hardware somewhere in the chain might also reject messages for various reasons, such as DNS records not being set up right.

* If the local mail server is set to relay through a list of other servers (e.g., for load balancing), one of the servers may be failing — a misconfigured firewall is blocking it, authentication is failing, whatever, hardware is dying, whatever.

* The mail server may be configured to avoid outgoing spam by rate-limiting you to a certain number of messages/hour, messages/day, messages/domain, messages at once, and so on.

* The receiving mail server may be using gray listing, and the sending mail server isn’t handling it properly.

* Some message content, such as certain strings of HTML and certain types attachments (or even attachment names), may cause the message to be blocked by anti-virus hardware/software somewhere along the way.

* Finally, make sure there’s not an error in your code. For example, maybe you’re trying to use a null object in some cases, or something else odd like that. Make sure error_reporting is cranked up and error_log is recording any notices/warnings/errors someplace where you can review them.

As a first step, make sure you’re checking the result of the mail() call. It’ll return a boolean to let you know whether it successfully handed off the message to the mail server. That doesn't mean it’ll get delivered, but at least you know the first handoff worked.

The next step is to check the mail server log, often /var/log/maillog. There, you can see information about how the local mail server is handing off to the receiving server (or to the relay server, if applicable). I’m spoiled in that I have full access to all of our application servers, but if you’re on a shared host, you’ll probably need the host’s help with this. (And note, if your code or your host’s mail servers are somehow at fault, switching away from mail() isn’t likely to help you.)

<small self-promotion>
It so happens that the company I work for offers a variety of hosting services, backed by a 24/7/365 US-based e-mail/chat/phone support team. If you are interested in learning more, let me know and I will have someone contact you. ‘Nuff said on that.
</small self-promotion>

Good luck!


Regards,
Bob

--
Robert E. Williams, Jr.
Senior Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/

Notice: This communication, including attachments, may contain information that is confidential. It constitutes non-public information intended to be conveyed only to the designated recipient(s). If the reader or recipient of this communication is not the intended recipient, an employee or agent of the intended recipient who is responsible for delivering it to the intended recipient, or if you believe that you have received this communication in error, please notify the sender immediately by return e-mail and promptly delete this e-mail, including attachments without reading or saving them in any manner. The unauthorized use, dissemination, distribution, or reproduction of this e-mail, including attachments, is prohibited and may be unlawful. If you have received this email in error, please notify us immediately by e-mail or telephone and delete the e-mail and the attachments (if any).

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux