SMTP module gives this warning after upgrading to D11.
Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\smtp\Plugin\Mail\SMTPMailSystem->mail() (line 341 of modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php).

Issue fork smtp-3516633

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mdsohaib4242’s picture

mdsohaib4242’s picture

mdsohaib4242’s picture

mdsohaib4242’s picture

gfbarbosa’s picture

Status: Active » Needs review
StatusFileSize
new1.25 KB

The module currently calls explode(',', $to) without checking if $to is null or a valid string. This triggers a deprecation warning in PHP 8.1 and above.

Reference:
https://www.php.net/manual/en/migration81.deprecated.php
https://stackoverflow.com/questions/71097927/php-8-1-explode-passing-nul...

This patch adds a check to ensure $to is a string or array before calling explode(). It handles the following scenarios:
- If $to is a string: it uses explode(',', $to)
- If $to is an array: it uses it directly
- If $to is null or empty: it skips the recipient loop

This prevents the deprecation warning and maintains compatibility with PHP 8.1+ and future versions.

tame4tex’s picture

@gfbarbosa thank you for the patch!

Are you able to contribute the patch as commits to the 3516633-deprecated-function-explode branch on the Issue Fork for this issue and then create a Merge Request? I would then be happy to review.

Here is more info on how to contribute to issues via Issue Forks and Merge Requests:
https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr...
https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr...

bluegeek9 made their first commit to this issue’s fork.

bluegeek9’s picture

Assigned: mdsohaib4242 » Unassigned

I made a simpler MR. According to hook_mail_alter $message['to'] is a string. The error message only mentions NULL. I do not think we need to check if $message['to'] is an array.

bluegeek9’s picture

Status: Needs review » Fixed
//www.flaticon.com/free-icons/thank-you Thank you for your contribution! Your continued support makes this project sustainable.
There are multiple ways to show appreciation for the work contributed to this project including:
  • Triage issues and adding more context to existing issues.
  • Flagging SMTP as a favorite on the project page to help others discover it and show your support.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • bluegeek9 committed 0e66e0cb on 8.x-1.x
    [#3516633] feat: Deprecated function: explode() by Bluegeek9
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mdsohaib4242’s picture

StatusFileSize
new6.21 MB