Make phpBB check return value of mail() function

Get help with installation and running phpBB 3.2.x here. Please do not post bug reports, feature requests, or extension related questions here.
Post Reply
User avatar
scootergrisen
Translator
Posts: 216
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

Make phpBB check return value of mail() function

Post by scootergrisen »

Sadly my host have a limit on how many emails can be sent.

And sadly phpBB just seem to say that the email have been sent regardless of it being sent or not.

This is not good because if a users tries to go to the contact us page and sent a email they get told it have been sent but it might not have happened if the host decides a limit have been reached.

So i suggest to check the return value of PHP mail() so that the user can be informed that sending the email failed and then show the message the user wrote on the page so the user still have the option to copy the text and try later or some other way.
User avatar
EA117
Registered User
Posts: 1858
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Make phpBB check return value of mail() function

Post by EA117 »

Edit: Actually, maybe I needed to start by asking, are you getting a failure message in the phpBB "Error log" visible from ACP Maintenance tab?

Because with regard to "checking the result" I think the answer is "phpBB already does that", and if there isn't an error log entry, then the point at which your host rejects or drops email that is over limit simply "is sometime after the sendmail process has already successfully completed." Or in some other way, does not result in an error of the mail process the host has setup to be invoked in response to the PHP mail() function. (You may be able to see the exact process your hosting provider has configured PHP to invoke for the mail() function in your PHP Info page.)

In /includes/functions_messenger.php, around line 1909, you can see the result of calling mail() being stored and returned. And you can see around line 633 at the point phpbb_mail() is called (as opposed to smtpmail()) that if the returned result is FALSE instead of TRUE, phpBB will report this in the error log. (Not withstanding that there will not be any details available for "why", unlike the SMTP case.)

So the implication is, "whatever mail sending process your host has configured for the PHP mail() function to execute" (whether that's the default sendmail process or something else) has actually returned success in the case you're observing. Else there would have been a phpBB error log entry.

You could try configuring phpBB use SMTP instead, if SMTP on localhost works for your hosting account, or your hosting account otherwise provides SMTP server and login information that you can configure phpBB to use. If their SMTP server rejects the over-limit email send attempt any differently, this error might then be reflected back through phpBB's SMTP client and reported as failure.

(Note not all hosts allow hosted web applications to make their own SMTP connections, in an effort to combat spam and getting the hosts' servers blacklisted. So you may need to ask your host for specifics on what information you can use to configure phpBB to use SMTP instead of the PHP mail() function.)
User avatar
scootergrisen
Translator
Posts: 216
Joined: Thu Aug 25, 2011 2:25 pm
Contact:

Re: Make phpBB check return value of mail() function

Post by scootergrisen »

I also have my own homemade contact form and when the limit was reached the contact form say the mail was not sent.

But using phpBB to sent a email just says the mail was sent no matter if i use SMTP or not and the mail is not sent.
It seems like the return value of mail() in phpBB is only checked for the sake of for putting a message in the log.
I would like it to be used for me message that user sees on the page to.



If i try using bulk mail to sent a message to all users i get 40 errors in phpbb log:

SMTP disabled:
E-mail-fejl
» EMAIL/PHP/mail()
/forum/adm/index.php
SMTP enabled:
E-mail-fejl
» EMAIL/PHP/mail()
/forum/cron.php
Its not a useful error messages.
I would rather have it say something like "PHP mail() function failed". "Unable to sent email to someone@someplace.somewhere".
When i get 40 identical errors in the log i have no way of telling them apart.
I just wonder why are there 40 if there are 2000 users.
Does 40 of the users have invalid emails maybe.

Also when i send bulk emails the information i get is not good it sounds like either the emails was sent successfully or there was some errors and then you are left wondering did it work.
And how do i check if it worked.
And which user ended up getting the email.
And which user ended up not getting the email.



So i would like better message for the user to see on the page and better error messages in the log.
That way users cant know when it fails and i can have an idea of way it failed by looking in the log.
User avatar
Mick
Support Team Member
Support Team Member
Posts: 22919
Joined: Fri Aug 29, 2008 9:49 am
Location: Watching cricket probably.

Re: Make phpBB check return value of mail() function

Post by Mick »

But the mail has gone from phpBB, what you’re talking about is how your mail provider handles emails. If phpBB isn’t sending email that’s a different story.
"The more connected we get the more alone we become" - Kyle Broflovski©
User avatar
david63
Registered User
Posts: 18570
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Contact:

Re: Make phpBB check return value of mail() function

Post by david63 »

scootergrisen wrote:
Wed Jul 31, 2019 10:36 am
So i would like better message for the user to see on the page and better error messages in the log.
That way users cant know when it fails and i can have an idea of way it failed by looking in the log.
As there is no facility within the core of phpBB to do that you have several options:
  1. Post in the Ideas Forum for it to be added to the code
  2. Request an extension
  3. Post in the Wanted Forum in the hope that somebody will be interested in doing it (for a price)
  4. Code it yourself
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored
User avatar
EA117
Registered User
Posts: 1858
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: Make phpBB check return value of mail() function

Post by EA117 »

scootergrisen wrote:
Wed Jul 31, 2019 10:36 am
So i would like better message for the user to see on the page and better error messages in the log.
Overall, I'd say you're correct on all points: The message logged in the case of phpBB being configured to use PHP mail() is not useful. And it would be better if the user knew that phpBB already knew that their email did not succeed.

After digging into the code a bit more, I see there are essentially two reasons why the user will never see that error:

First, the default of phpBB is to "queue" the email rather than sending it directly and immediately, as controlled through the "Email package size:" setting in the ACP Email Settings page. When this configuration is set to a non-zero value (as it is by default), the "success" being seen when sending email is "successfully queued", not "successfully sent" yet. phpBB will perform the actual email send at some other time, after the user has already left the email sending page and might not even still be using the site.

Second, although functions_messenger.php was tracking, logging and returning the failure status as described, this failure status is not actually examined by the higher-level callers of the Messenger::send or Messenger::submit functions. So even if you did change the "Email package size:" to zero such that the mail was being sent synchronously, the high-level reaction shown to the user still wouldn't reflect the error status, just as you described. The error log message would still be the only evidence of failure.

Obviously the error log message could be improved relatively easily. So I would suggest keeping that proposal separate, since the idea really stands on its own, and there isn't really anything for someone to "be against." And since arguably, for most environments, notifying the administrator that an email failed "is enough", since it's not typical that "all email starts failing every day due to how much email was sent."

Suggesting that "the email sending failure should be surfaced back to the user" has many more challenges, only one of which is the whole "queuing" aspect mentioned earlier. But nonetheless, it still seems like a valid idea. You can expect some push-back on it, and perhaps reasonably so, since essentially you're looking to "design phpBB for the failure" of email that stops working every day due to usage. Rather than eliminating that failure, such that the condition of "email failure" moves back closer to being "a rare and administrator error log-only occurrence" as would probably be characterized by "most phpBB users."

But as David indicated, there is nothing you're able to do in standard phpBB settings in order to create either of those outcomes. Changing the "Email package size:" to zero moves the needle a little closer to where it could be "possible" to do something, but still ultimately does not help.
Post Reply

Return to “[3.2.x] Support Forum”