Daily Lucky Numbers:
4
13
23
26
34
43

Zhen Mailer version 1.3

Started by Chen Zhen, January 25, 2020, 04:12:25 PM

Previous topic - Next topic

Chen Zhen

SMF 2.0.X branch:
Adds STARTTLS-SMTP compatibility & extra utilities for your SMF outbound email.

SMF 2.1.X branch:
Adds utilities for your SMF outbound email.


Zhen Mailer

Version 1.3


Notations:

PHP Mail Users:

Mail server software such as Postfix have a message size limit setting.
If you have a large database and are using the DB backup option you may need to increase this limit to a rather large number.
The setting is usually in Bytes and is based on the decompressed size of each file.
Even though files are compressed, your email program will decompress them to send the data.
This setting should be available in your Control Panel or you can manually adjust a config file if you have that option available.

Postfix reference example

This version concerns major changes and bug fixes.

Zhen Mailer is no longer restricted to SMTP email usage.
People using regular PHP mail may now take advantage of this utility.
If you operate a VPS or dedicated server and need help installing any of the requirements, please feel free to leave a post in the forum.


Branch differences:
SMF 2.1 offers a bit more flexibility due to its structure and use of more hooks compared to the SMF 2.0 branch.
Multiple emailed attachments from a single post in the SMF 2.1 branch will be sent as one email.
SMTP usage is no longer mandatory for this utility as it now supports regular PHP email.

However for the SMF 2.0 branch, it will send an email for each attachment even if all of them are from a single post.
SMTP-STARTTLS support is added for this branch as it is not normally available in SMF 2.0.X.


Zhen Mailer Admin Setting ~ Admin/User ID To Send DB Dumps
Be careful when adding an additional user email address to the sent database and/or attachment emails.
Ensure that the extra email address is one that should be receiving those emails (ie. an admin)


This installation process will add the following:

-> Database dumps that are forwarded to the webmaster email and/or an additional admin email.
-> Attachment backups to the webmaster email and/or an additional admin email as they are posted
-> STARTTLS-SMTP compatibility for use of 3rd party email providers (not necessary when using a properly configured PHP mail transfer client)
-> Options to encrypt any email attachments as compressed zip archives (requires PHP 7.2+ & ZipArchive)

Compatibility notes:
- PHP version 5.5 with the openssl PHP extension enabled is the minimum requirement for STARTTLS-SMTP compatibility
- ZipArchive extension is required for compression of any attachment backups
- PHP version 7.2+ with the ZipArchive extension is required for any archive encryption
- cURL extension is required for the scheduled database dumps option

This will allow your forum to use SMTP email using gmail, hotmail or yahoo mail.
PHP version 7.2+, ZipArchive & cURL extensions are recommended to make full use of this modification.

Updated CA certificates are required for your forum to communicate with email providers using the STARTTLS SMTP extension.
Example settings for your php.ini file may be:
openssl.cafile = /etc/ssl/cacert.pem
curl.cainfo = /etc/ssl/cacert.pem

You can download the latest cacert.pem file here:
https://curl.haxx.se/ca/cacert.pem

Other Notes:
Although it is not mandatory, a mail user named "members" should be created for BCC bulk emails.
SMTP port 587 is recommended.


Zhen Mailer for Simple Machines Forum
c/o Chen Zhen @ web-develop.ca
@license  http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@copyright 2022 Chen Zhen

3rd Party Usage:
PHPMailer - PHP email creation and transport class.
@license  http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@author    Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
@copyright 2012 - 2017 Marcus Bointon

Shuttle-Export c/o 2createStudio
PHP based MySQL dump library
@license  http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
@copyright 2015 - 2017 2createStudio

Distributed under the GNU Lesser General Public License -> https://www.gnu.org/licenses/lgpl.html

CLICK HERE TO DOWNLOAD ZHEN MAILER

weezel

#1
After updating my 2.0.19 forum host to PHP8.0, emails are no longer being sent. Zhen Mailer shows this error when accessing Zhen mailer settings...

implode(): Argument #2 ($array) must be of type ?array, string given

No errors are showing elsewhere.

This is running the latest version 1.3

Had to revert back to PHP 7.4  :'(
Hope it's fixable. Thanks for all your mods. You really are a coding wizard  ;D


Chen Zhen

#2
Can you give the file & line that the error showed in the log?

Nevermind.. I found it right away when testing on PHP 8.
I will release a fix for it shortly & thanks for the report.

Chen Zhen


Version 1.3.2 is now available which includes a fix for what was reported.

weezel

Hi,
Well tried your 1.3.2 version and good and bad news. Good news is that it no longer shows an error.
Bad news is that it is still not sending any mail. This is with the mail type set as the default PHP setting.
Reverted back to PHP 7.4 and mail is then sent OK.
No errors are seen in the Admin logs.
Thanks for the quick response anyway  :)

Chen Zhen

#5
This sounds as though some PHP settings need to be adjusted for PHP 8.0.
Compare your PHP 7 php.ini file to your PHP 8 php.ini file.

Check to see if these variables are set to the same values:
openssl.cafile
curl.cainfo
sendmail_path
error_log

Your PHP error log will likely show whatever error is occurring (not the SMF error log).

If you make changes to that file, you'll need to reset Apache afterward.




More than likely it's the sendmail_path that is not configured correctly.
Make sure you remove the semicolon prior to the setting when you want to use/adjust it because that acts as a comment & is ignored when a line starts with it.

weezel

#6
Hi again,
Well I've checked both PHP configs and they look the same.
For some reason, my php  error log has not updated for 2 yrs, even though error logging is enabled.
Something else to look into at some point  ::)
I have a test SMF forum running 2.12 on the same shared hosting server and that sends mail fine when running PHP8.0 using default PHP mail type, so I don't see how the server config can be at fault.
Guess I'll have to try and get the logging sorted to see what the issue is.
I'll report back if I finally get the mail working.
Many thanks for your time.

Chen Zhen

When using PHP FCGI there will likely be 2 php.ini files.
One is the default which is available when installed but when running multiple PHP versions a secondary php.ini is created.
The secondary is the one that takes affect.
This is shared hosting? Is your only way of accessing the php.ini file via a control panel?

Also set your mail.log path from the php.ini file.
Both the error_log & mail.log file paths should be created plus Apache should have ownership + permissions to use the file(s).

Is it only Zhen Mailer that isn't working?
Does your PHP mail work just using SMF itself?
Admin -> Mail -> Send Test

If it doesn't work at all only with PHP 8.0 then something is awry with a config file native to that PHP version.

Check your admin email for spam and/or all mail.
If the mail headers aren't correct then it will be sent through as spam.



weezel

Thanks for the tips, however I've taken an easier route as I don't have sufficient privileges to change those PHP.ini settings.
I had to stop using Gmail in the past as they changed their authentication requirements.
Then you came along with Zhen mailer, which got the mail working again on PHP7.4 using the default PHP mail  :)
However, by setting ones Gmail account to use TFA and an application password, putting that password in the SMF STARTTLS-SMTP mail settings works fine on PHP8.0.
Thanks and enjoy the rest of your day, you deserve it  ;)

Chen Zhen

Free SMTP email can be very restrictive.
They give you a daily limit for emails so ie. if you have new registers confirm their email & a spambot targets your domain with multiple registrations it will stop the emails for that day. Other things also use up email quota such as notifications that you have setup on your forum.
I've run into that scenario & use PHP mail from that time forward.

It's working for you so that's great but if you see that emails are being stopped via that process then what I just mentioned may be the reason.

Chen Zhen

#10
@weezel:

Please note the PR for SMF 2.1 regarding mail & carriage returns in the header:
https://github.com/SimpleMachines/SMF/pull/7560/files/a1ed0497bfec22db968bef24ea0e3080c83f4921

SMF 2.0.19 has the same issue therefore PHP emails may fail when using PHP 8+.
ZhenMailer already uses the appropriate CR that is needed for PHP8+ although it might explain any issues people have with older PHP versions.

I know you decided to go with SMTP email but I'm curious to know if you were referring to ZhenMailer having an issue with DB dumps or was SMF not sending any emails at all?
Those don't use the same SMF function to send emails as ZhenMailer has its own for sending DB dumps.

If you were only having problems with sending regular SMF emails with php mail(), SMF 2019 & PHP 8+ then an edit will likely fix it.

file: ../Sources/Subs-Post.php

find:
$line_break = $context['server']['is_windows'] || !$use_sendmail ? "\r\n" : "\n";

replace with:
$line_break = ($context['server']['is_windows'] || !$use_sendmail || version_compare(PHP_VERSION, '8.0.0', '>=')) ? "\r\n" : "\n";



Keep in mind if the SMF devs release a SMF 2.0.20 patch then you may need to revert the edit prior to applying the patch or perhaps ignoring the parsing error you'll get when it attempts to make this very same edit.