[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP, FIX, ENH] maillib.php: Fix sendmail command flags for Symfony Mailer

"Sammy Ndabo \(@ndabosam084\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <69146b46c7a8c_2ce2fcc273b8@gitlab-sidekiq-low-urgency-cpu-bound-v2-f8dc7c8b7-v5b6w.mail>

Sammy Ndabo pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
437a1194 by Sammy Ndabo at 2025-11-12T11:02:21+00:00
[BP, FIX, ENH] maillib.php: Fix sendmail command flags for Symfony Mailer
---
* [FIX, ENH] maillib.php: Fix sendmail command flags for Symfony Mailer
---
* [FIX] maillib: update mailer handler name from 'customsendmail' to 'phpini' for clarity

* [ENH] maillib: improve email sending by utilizing Envelope mailer class for sender information

* [ENH] maillib: add customizable sender email option for sendmail command

* [FIX, ENH] maillib: ensure sendmail://default dsn is used by default and added a new option to customize which send mail conf to use via php.ini

* [ENH] tiki-check.php: add note regarding the fact that proc_open function is needed by Sendmail

* [ENH] iinclude_general.tpl: add info about needed function for sendmail

* [NEW, ENH] maillib: enhance bin path to be customizable using pref with default value, added new option for php mail function using symfony buitlin transports native, which rely on php.ini

* [FIX] maillib: Fix sendmail command flags for Symfony Mailer

See merge request tikiwiki/tiki!8878

(cherry picked from commit d9a0987e6079633a3b6f543231f7f46f52b93e32)

See merge request tikiwiki/tiki!9013

- - - - -


4 changed files:

- lib/mail/maillib.php
- lib/prefs/mailer.php
- templates/admin/include_general.tpl
- tiki-check.php


Changes:

=====================================
lib/mail/maillib.php
=====================================
@@ -27,6 +27,7 @@ use Symfony\Component\Mailer\Bridge\Mailchimp\Transport\MandrillTransportFactory
 use Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory;
 use Symfony\Component\Mailer\Bridge\Postmark\Transport\PostmarkTransportFactory;
 use Symfony\Component\Mailer\Bridge\Sendgrid\Transport\SendgridTransportFactory;
+use Symfony\Component\Mailer\Envelope;
 use Symfony\Component\Mailer\Mailer;
 use Symfony\Component\Mailer\MailerInterface;
 use Symfony\Component\Mailer\Transport;
@@ -110,8 +111,10 @@ function tiki_mail_setup()
         if (! empty($queryParameters)) {
             $dns .= "?" . implode("&", $queryParameters);
         }
-    } elseif (! empty($prefs['mailer_handler']) && $prefs['mailer_handler'] === 'sendmail' && ! empty($prefs['sender_email'])) {
-        $dns = "sendmail://default?command=" . urlencode('-f' . $prefs['sender_email']);
+    } elseif (! empty($prefs['mailer_handler']) && $prefs['mailer_handler'] === 'sendmail') {
+        $dns = "sendmail://default";
+    } elseif (! empty($prefs['mailer_handler']) && $prefs['mailer_handler'] === 'phpini') {
+        $dns = "native://default";
     } elseif (! empty($prefs['mailer_handler']) && $prefs['mailer_handler'] === 'file') {
         $mail_debug_path = TIKI_PATH . '/' . TEMP_MAIL_DEBUG ;
         if (! file_exists($mail_debug_path)) {
@@ -225,11 +228,23 @@ function tiki_send_email($email)
         $email->bcc([]);
     }
 
+    $envelope = null;
+    if (! empty($prefs['sender_email'])) {
+        try {
+            $envelope = Envelope::create($email);
+            $senderName = $prefs['sender_name'] ?? null;
+            $envelope->setSender(new Address($prefs['sender_email'], $senderName));
+        } catch (Throwable $e) {
+            error_log("Mailer Envelope Error: " . $e->getMessage());
+            $envelope = null;
+        }
+    }
+
     /* @var $tiki_maillib__mailer_default_transport  */
     global $tiki_maillib__mailer_default_transport;
 
     try {
-        $tiki_maillib__mailer_default_transport->send($email);
+        $tiki_maillib__mailer_default_transport->send($email, $envelope);
     } catch (TransportExceptionInterface $e) {
         error_log("Mailer Transport Error: " . $e->getMessage());
     } catch (Throwable $e) {


=====================================
lib/prefs/mailer.php
=====================================
@@ -9,7 +9,8 @@ use Tiki\Package\VendorHelper;
 function prefs_mailer_list()
 {
     $emailOptions = [
-        'sendmail' => tra('Sendmail'),
+        'sendmail' => tra('Sendmail (sendmail binary)'),
+        'phpini' => tra('Php.ini mail settings'),
         'smtp' => tra('SMTP'),
         'file' => tra('File (debug)'),
     ];
@@ -151,7 +152,7 @@ function prefs_mailer_list()
         ],
         'mailer_handler' => [
             'name' => tra('Mail sender'),
-            'description' => tra('Specify if Tiki should use Sendmail(the PHP mail() function), SMTP or File (Debug) (to debug email sending by means of storing emails as files on disk at ./temp/Mail_yyyymmddhhmmss_randomstring.tmp ) to send mail notifications.'),
+            'description' => tra('Specify if Tiki should use the system Sendmail binary, the PHP mail() settings from php.ini, SMTP, or File (Debug) (to debug email sending by means of storing emails as files on disk at ./temp/Mail_yyyymmddhhmmss_randomstring.tmp ) to send mail notifications.'),
             'type' => 'list',
             'options' => $emailOptions,
             'default' => 'sendmail',


=====================================
templates/admin/include_general.tpl
=====================================
@@ -60,6 +60,11 @@
                     {preference name=mailer_spark_post_key}
                     {preference name=mailer_spark_post_region}
                 </div>
+                <div class="adminoptionboxchild mailer_handler_childcontainer phpini">
+                    {remarksbox type="warning" title="{tr}PHP mail() limitations{/tr}"}
+                        {tr _0='<a href="https://symfony.com/doc/current/mailer.html#using-built-in-transports" target="_blank" rel="noopener">' _1='</a>'}This uses PHP’s mail() settings from php.ini (sendmail_path or SMTP). Because it relies on the host configuration, delivery errors may be hidden and Bcc headers might be exposed. Prefer the Sendmail or SMTP options when possible. See %0Symfony’s mailer documentation%1 for details.{/tr}
+                    {/remarksbox}
+                </div>
                 <div class="adminoptionboxchild mailer_handler_childcontainer smtp">
                     {preference name=mailer_smtp_server}
                     {preference name=mailer_smtp_auth}


=====================================
tiki-check.php
=====================================
@@ -2870,11 +2870,11 @@ $fcts = array(
             'risky' => tra('System is similar to exec.') . ' ' . tra('Tiki does not need it; perhaps it should be disabled.'),
             'safe' => tra('System is similar to exec.') . ' ' . tra('Tiki does not need it; it is good that it is disabled.')
          ),
-         array(
+        array(
             'function' => 'proc_open',
-            'risky' => tra('Proc_open is similar to exec.') . ' ' . tra('Tiki does not need it; perhaps it should be disabled. However, the Composer package manager used for installations in git checkouts or when using the package manager from the <a href="https://doc.tiki.org/Packages" target="_blank">admin interface</a> may need it.'),
-            'safe' => tra('Proc_open is similar to exec.') . ' ' . tra('Tiki does not need it; it is good that it is disabled. However, the Composer package manager used for installations in git checkouts or when using the package manager from the <a href="https://doc.tiki.org/Packages" target="_blank">admin interface</a> may need it.')
-         ),
+            'risky' => tra('Proc_open is similar to exec.') . ' ' . tra('Tiki does not need it; perhaps it should be disabled. However, the Composer package manager used for installations in git checkouts or when using the package manager from the <a href="https://doc.tiki.org/Packages" target="_blank">admin interface</a> may need it.') . ' ' . tra('The Sendmail mailer option also requires it.'),
+            'safe' => tra('Proc_open is similar to exec.') . ' ' . tra('Tiki does not need it; it is good that it is disabled. However, the Composer package manager used for installations in git checkouts or when using the package manager from the <a href="https://doc.tiki.org/Packages" target="_blank">admin interface</a> may need it.') . ' ' . tra('The Sendmail mailer option also requires it.')
+        ),
          array(
             'function' => 'popen',
             'risky' => tra('popen is similar to exec.') . ' ' . tra('Tiki needs it for file search indexing in file galleries. If this is needed and other PHP software on the server can be trusted, this should be enabled.'),



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/437a11940fb59037d5646233d6f34b6d53acd0dd

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/437a11940fb59037d5646233d6f34b6d53acd0dd
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.