PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Anyone see anything wrong with this? It's just a simple mailer, sometimes it works perfectly for months and sometimes it just won't send mail at all...
Yeah it's just a small script which get's distrubuted so I don't want to add a bunch of code to it for mailing. Swiftmail would be overkill for the needs.
In the context that this function is used, it would be impossible for header injection unless someone cracked into the MySQL server and modified a varchar field.
Do you see anything in it which would cause emails not to be sent though? I know it's receiving valid data.
Since I'm not as well versed in the eccentricities of mail as some, I can't really say. Once d11 comes back around, he may have some comments however. Sit tight.
Multiple extra headers should be separated with a CRLF (\r\n).
Not: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing.
Not: If messages are not received, try using a LF (\n) only. Some poor quality Unix mail transfer agents replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with RFC 2822.
I'll go ahead and change them but I'm not sure that would cause it to work intermitently on a server when nothing has been changed.
It may not be a direct problem on you server, but on a relay down the line. This can be especially true if the route often taken changes for some reason. Some email servers are more strict than others.
Ok, that makes sense, just so we are all on the same page, here is a note from a client..
now I called host they said no mail is going out from the script it has no returnpath so it just goes into thin air... he said the script is not sending any mail its in QUE and he need an error message to find out whats wrong
This isn't valid since the comma has a special meaning. Usually you can leave out the "quotes" but not if you have a comma there. You need it to be:
"Firstname, Lastname" <address>
If you're really sending such a short email then that can cause you a problem. Also, if you want to send anything outside US-ASCII ranges then you almost certainly need to use Swift (or an alternative if you don't like Swift). 8-bit sequences (the £ sign is one that commonly catches people out) are a definite no-no.
Using Swift or otherwise, have a read over this, check the blacklist database linked to in there and check you have a SPF record.