LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-24-2017, 12:03 PM   #1
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Rep: Reputation: 58
php mail() not reaching some destinations


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?
 
Old 05-24-2017, 01:34 PM   #2
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,467
Blog Entries: 6

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
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.

Here is a good discussion of the possible causes.

For anyone here to help we will need to know what the actual caause is.
 
1 members found this post helpful.
Old 05-24-2017, 07:29 PM   #3
scasey
Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 5.11
Posts: 335

Rep: Reputation: 122Reputation: 122
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?
 
2 members found this post helpful.
Old 05-25-2017, 02:26 PM   #4
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Thank you astrogeek. I've looked at the link and will follow the suggestions therein.

Quote:
Originally Posted by scasey View Post
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'
 
Old 05-25-2017, 02:57 PM   #5
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Quote:
Originally Posted by scasey View Post
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.
 
Old 05-25-2017, 05:33 PM   #6
scasey
Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 5.11
Posts: 335

Rep: Reputation: 122Reputation: 122
Quote:
Originally Posted by dogpatch View Post
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?

Last edited by scasey; 05-25-2017 at 05:34 PM.
 
1 members found this post helpful.
Old 05-25-2017, 08:24 PM   #7
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Quote:
Originally Posted by scasey View Post
Yup. That simple.
So . . . i could simply eliminate that line from my header, or lie, and say it's something other than php??
 
Old 05-25-2017, 08:32 PM   #8
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
According to this page, that's exactly what many spammers are doing - eliminating the X-Mailer header line.

I loath to stoop to spammers' tactics, but it may be what i have to do. Or, do you suppose this would create additional risks of rejection?

Last edited by dogpatch; 05-25-2017 at 08:36 PM. Reason: add final question
 
Old 05-25-2017, 08:41 PM   #9
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Quote:
Originally Posted by scasey View Post
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.
 
Old 05-26-2017, 07:17 PM   #10
scasey
Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 5.11
Posts: 335

Rep: Reputation: 122Reputation: 122
Quote:
Originally Posted by dogpatch View Post
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 View Post
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?
 
1 members found this post helpful.
Old 05-27-2017, 10:08 AM   #11
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Quote:
Originally Posted by scasey View Post
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.
 
Old 05-27-2017, 10:23 AM   #12
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,458

Rep: Reputation: Disabled
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 common blocklist databases?
 
2 members found this post helpful.
Old 05-27-2017, 11:53 AM   #13
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 257
Blog Entries: 1

Original Poster
Rep: Reputation: 58
Unhappy

Quote:
Originally Posted by Ser Olmy View Post
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 common blocklist databases?
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?
 
Old 05-27-2017, 01:10 PM   #14
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,458

Rep: Reputation: Disabled
Quote:
Originally Posted by dogpatch View Post
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 View Post
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 View Post
It would seem, if these are my problem, i may be dead in the water?
Not at all.

Last edited by Ser Olmy; 05-27-2017 at 02:18 PM.
 
2 members found this post helpful.
Old 05-27-2017, 01:42 PM   #15
scasey
Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 5.11
Posts: 335

Rep: Reputation: 122Reputation: 122
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?

Last edited by scasey; 05-27-2017 at 03:55 PM.
 
2 members found this post helpful.
  


Reply

Tags
email, php. mail()


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Postfix: Restricting what users can send mail to off-site destinations blaszta Linux - Newbie 7 02-12-2013 12:00 AM
[SOLVED] Restricting some users send mail to off-site destinations in sendmail mail4vijay Linux - Server 2 10-23-2009 03:20 AM
PHP - Mail.php and Mail/mime.php issues LVsFINEST Linux - Server 1 02-08-2009 05:44 PM
relay all non-local mail to 1 local address and NOT real destinations manqox Linux - Server 6 09-04-2008 04:13 AM
Exim : Mail reaching but... vikasumit Linux - Software 0 06-27-2006 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration