[SOLVED] php mail() not reaching some destinations
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Have been using php mail() to send emails, for convenience. Almost always works. But occasionally it seems as if the email never reaches its destination. It seems certain addresses are unreachable unless i use gmail, etc.
What, i anything, can i do to remedy this, or at least to get some feedback that the email was never delivered?
This probably has nothing to do with php, and is likely due to the configuration of the host from which you are sending or the result of the sendeing IP address being on someone's blacklist.
I have often considered writing a spam filter that blocks email sent by php mail. It seems that it's almost always spam. I've not done that yet, as reports to hosting ISPs continue to be effective. Still...
Do you get a failure/rejection message? From which mailserver does it come? What does it say?
Thank you astrogeek. I've looked at the link and will follow the suggestions therein.
Quote:
Originally Posted by scasey
Do you get a failure/rejection message? From which mailserver does it come? What does it say?
I used mail() to send myself an email at my gmail address. Gmail did indeed put it into the spam folder. Gmail gave me some possible causes, one of which was a faulty or suspicious 'Return-Path' in the header. I 'taught' Gmail to accept my own php mail by saying it wasn't spam. But perhaps this is what other mail servers are also burping on?? If so, i don't know how to remedy it. Tried to specify my own Return-Path, but my hosting server replaces anything i enter with their own Return-Path.
Last edited by dogpatch; 05-25-2017 at 08:42 PM.
Reason: correct spelling of 'astrogeek'
I have often considered writing a spam filter that blocks email sent by php mail.
How would your filter work? How can you tell that the email was sent by php? By looking at the 'X-Mailer' line in the header? Surely not something so simple.
How would your filter work? How can you tell that the email was sent by php? By looking at the 'X-Mailer' line in the header? Surely not something so simple.
Yup. That simple.
Quote:
Do you get a failure/rejection message? From which mailserver does it come? What does it say?
See my second post above (4th post overall in this thread).
Also, i am now including a 'return-receipt-to' header, and see if that yields any clues.
In #4 you report on a successful delivery to gmail that was received and delivered to your spam folder.
Your OP said
Quote:
Originally Posted by dogpatch
But occasionally it seems as if the email never reaches its destination
When that happens (when delivery fails), do you get a failure/rejection message? From which mailserver does it come (yours or the foreign server)? What does it say?
When that happens (when delivery fails), do you get a failure/rejection message? From which mailserver does it come (yours or the foreign server)? What does it say?
No, i've never gotten a failure/rejection message returned to me. Two days ago i included the 'return-receipt-to' header, and have sent one email since then that my contact says she never received. I didn't get a failure message from that one, either.
Have you configured SPF records for the DNS domain of the sender address? Without SPF, your mails could be flagged as spam for any number of reasons.
Also, have you checked if your server's public IP address might be listed in the most commonblocklistdatabases?
This script is running on an inexpensive hosting service. I can't see any facility in my cpanel where i might create and/or modify SPF records, even if i were well-versed in what they are and what they do.
Not even sure how to know what is my server's IP address.
It would seem, if these are my problem, i may be dead in the water?
This script is running on an inexpensive hosting service. I can't see any facility in my cpanel where i might create and/or modify SPF records, even if i were well-versed in what they are and what they do.
You don't create SPF records on your server, you do that in the DNS domain of the sender e-mail address.
For instance, if you're sending e-mails from phpmailer@mydomain.com, there should be an SPF record in mydomain.com indicating that your server is a valid source of mails from that domain.
SPF records are nothing but DNS TXT records containing text in a very specific rule format, and the rule exists to inform receiving servers how they should view mails claiming to come from an account in the domain in question. This makes it far easier to block spam, and it also happens to reduce the number of false positives. There's a decent Wikipedia article on SPF, including an example.
So the question then is, what is the From: address(es) used in these e-mails?
Quote:
Originally Posted by dogpatch
Not even sure how to know what is my server's IP address.
Visit a site like http://whatismyipadress.com from the server, or take a look at the source of an e-mail sent by the server; it will contain a number of "Received:" headers, showing the hostnames and IP addresses of every server involved in the delivery of the message.
Quote:
Originally Posted by dogpatch
It would seem, if these are my problem, i may be dead in the water?
It occurs to me this morning that php mail is "mail client" software...that is, it is the MUA and must be using some MTA to actually send the email.
What is the MTA (mail transport agent) you're using? Sendmail or postfix or qmail on your server? Your ISPs MTA?
If you're not getting bounces, then your mail IS most probably being delivered. All mail servers are "required" to report BOUNCES to the sender when mail cannot be delivered as addressed, even those rejected as spam by the RBLs or by the receiving server's spam filters. Review the link astrogeek posted in #2 above. If the "sender" isn't you, then the BOUNCES are going elsewhere.
We could tell how your mail is being sent from the headers, as Ser Olmy suggested...the challenge being that sanitizing them for a post would likely obfuscate what we need to see. To figure it out yourself, put "how to read email headers" into your favorite search engine. Those links will talk about both how to see the headers and what they mean.
As was stated earlier, (again, by astrogeek in #2) this is unlikely to be a php mail issue and more likely due to the MTA configuration, or your use of it. We really need to know who/what is delivering your mail. What are the values of SMTP and sendmail_path in your php.ini?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.