After updating SMTP using the drupal admin site, SMTP did not work anymore and I received the following error on status page:

6.1.3
PHPMailer library 6.1.5 or higher is required. Please install a newer version by executing 'composer update' in your site's root directory.

After digging some hours around I want to share my findings for further improvement of the module.

Install PHPMailer

After installation of phpmailer/phpmailer using

composer require phpmailer/phpmailer

this was the output of composer show phpmailer/phpmailer:

name     : phpmailer/phpmailer
descrip. : PHPMailer is a full-featured email creation and transfer class for PHP
keywords :
versions : * v6.1.6
type     : library
license  : GNU Lesser General Public License v2.1 only (LGPL-2.1-only) (OSI approved) https://spdx.org/licenses/LGPL-2.1-only.html#licenseText
homepage :
source   : [git] https://github.com/PHPMailer/PHPMailer.git c2796cb1cb99d7717290b48c4e6f32cb6c60b7b3
dist     : [zip] https://api.github.com/repos/PHPMailer/PHPMailer/zipball/c2796cb1cb99d7717290b48c4e6f32cb6c60b7b3 c2796cb1cb99d7717290b48c4e6f32cb6c60b7b3
path     : /var/www/html/vendor/phpmailer/phpmailer
names    : phpmailer/phpmailer

autoload
psr-4
PHPMailer\PHPMailer\ => src/

requires
ext-ctype *
ext-filter *
php >=5.5.0

requires (dev)
doctrine/annotations ^1.2
friendsofphp/php-cs-fixer ^2.2
phpunit/phpunit ^4.8 || ^5.7

suggests
ext-mbstring Needed to send email in multibyte encoding charset
hayageek/oauth2-yahoo Needed for Yahoo XOAUTH2 authentication
league/oauth2-google Needed for Google XOAUTH2 authentication
psr/log For optional PSR-3 debug logging
stevenmaguire/oauth2-microsoft Needed for Microsoft XOAUTH2 authentication
symfony/polyfill-mbstring To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)

Anyway, on the status page (also after clearing the cache using webinterface and drush (drush cache:rebuild)) there was still the error mentioned above.

Manually copying the file to smtp module dir

This post led me to the right path: https://www.drupal.org/project/smtp/issues/3135015#comment-13615693

I carried out these steps:

  1. mkdir -p modules/smtp/lib/phpmailer-phpmailer/v6.1.5/src/
  2. cp -r vendor/phpmailer/phpmailer/src/* modules/smtp/lib/phpmailer-phpmailer/v6.1.5/src/
  3. Verify: ls -l modules/smtp/lib/phpmailer-phpmailer/v6.1.5/src/
  4. Rebuild permission (consider this as optional): chown -R www-data /var/www/html; chgrp -R www-data /var/www/html; find . -type d -exec chmod u=rwx,g=rx,o= '{}' \; find . -type f -exec chmod u=rw,g=r,o= '{}' \;
  5. Now the error message persists, but the module is working again...
CommentFileSizeAuthor
#10 composer.jpg136.54 KBjshimota01
#10 package.jpg95.75 KBjshimota01
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

lobo_ created an issue. See original summary.

emscha’s picture

Following your steps, still having issues with 8.x-1.0-rc3 and PHPMailer.

Disabled fields are overridden in site-specific configuration file.

Unable to send email. Contact the site administrator if the problem persists.

Also using Ludwig, installing library at modules/smtp/lib/phpmailer-phpmailer/^6.1.5. The newest version, 6.1.6, has a security update: https://github.com/PHPMailer/PHPMailer/releases/tag/v6.1.6. SMTP Module ludwig json file is using 6.1.5.

Previous version, 8.x-1.0-beta7, worked perfectly fine until the module released 8.x-1.0-rc3.

Installing with composer, similar issues. Any advice on how to get it to work? thanks

Cayenne’s picture

Joining in here. I have spent several hours in this with a wide range of permutations. Trying all above suggestions. A simple definitive statement of WHAT FILE(s) GOES EXACTLY WHERE would be really helpful here.

Pantheon is not composer-friendly, or I'd be using it.

My current error:

Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in Drupal\smtp\Plugin\Mail\SMTPMailSystem->mail() (line 157 of /code/modules/smtp/src/Plugin/Mail/SMTPMailSystem.php)

awasson’s picture

I'll join in here too.

Presently I have one site out of 30 that I maintain that uses a Composer workflow so an alternative guide to using Composer to maintain my instances of SMTP will be very useful. For the time being I will hold off on updating it.

Andrew

bill_redman’s picture

I'm using version 8.x-1.0-rc3 and PHPMailer 6.1.5 and I discovered a similar issue except mine was:

SMTP cannot be enabled because the PHPMailer library is missing

I followed the steps above, I've uninstalled and re-installed the module, I've cleared caches all to no avail.

What is even more puzzling for me is I have another site using the same version of the module and it has the PHPMailer library in vendor/phpmailer/phpmailer/src and it is working fine.

I even tried placing the library in that same location on the problem site and it made no difference. Same library missing error.

So, if anyone has any suggestions as to what else I might look at or compare between my working site and non-working site, it will be most appreciated.

UPDATE: I tried -rc1 & -rc2 and encountered the same problem. I then rolled back the module to version, 8.x-1.0-beta7 and it is once again working as it should.

japerry’s picture

This sounds like an issue with the autoloader for composer projects, not with SMTP module itself. I know that doesn't give a lot of confort, but not sure what else we can do. A common cause is having your vendor directory outside the docroot without the autoloader link being correct.

return require __DIR__ . '/../vendor/autoload.php';
vs
return require __DIR__ . '/vendor/autoload.php';

lodey’s picture

I had this problem when I installed SMTP without composer and forgot to place the phpmailer in vendor BEFORE turning on the module.

After placing phpmailer folder in the vendor folder, it would not register it. I had to uninstall the SMTP module and reinstall it for it successfully recognise it.

awasson’s picture

@lodey, great tip. Thanks for that. I will give it a shot.

brandon_’s picture

Does anyone having this specific issue (ie v6.1.3 of phpmailer installed) also have SimpleSAMLphp installed?

I had this issue, and I also have a SimpleSAMLphp instance running together with my Drupal installation. I had installed SimpleSAMLphp using their downloadable package, which also includes phpmailer 6.1.3.

Until the SimpleSAMLphp packages are built with updated modules, you can try to manually replace the old phpmailer package with a newer one you already have in your Drupal installation (which seems to be working for me), or possibly install SimpleSAMLphp using git and composer, or even separate the two installations completely.

Also, if you don't have SimpleSAMLphp installed, but still have this error, try searching around for any other phpmailer installation that might be on your system.

jshimota01’s picture

FileSize
95.75 KB
136.54 KB

Potentially useful information -
I'm am a composer based installation- using the 8.9.x environ. Normally I run manually updates on modules after I research them - I recently applied a 'composer update' without specifying anything and one module, phpmailer/phpmailer went from 6.15 to 6.17. I also run Ludwig so I can see library packages from the GUI of the website.
My package shows PHPmailer as missing. it also suggests 6.15. My phpmailer library is inplace but is now in the vendor folder, but NOT in the location it had been previously. In fact, the whole folder '/lib' had been blown out.
In my modules folder, looking at the SMTP module I have a Ludwig.json which I can't recall how it got there and it also references a hard code reference to the 6.15 zip.
Attached are 2 quick Images to assist in seeing my version of this problem. I think the module is not checking the PHPMailer location in vendor first before referencing it's own library location but I'm not a programmer.
For now I"m manually copying the PHPmailer from the 6.17 in Vendor into the 6.15 so Ludwig is happy, and the SMTP module functions. Very interested in someone figuring this out!
thanks.

japerry’s picture

Status: Active » Fixed

I pushed an update that changes the version to the most recent: 6.1.7. I didn't notice until now that the original report showed 6.1.3 installed, or at least detected, which would explain why smtp threw this error. This update also fixes a security issue with the underlying library.

To be clear, while Ludwig is included with the SMTP module, it is NOT recommended or supported. The only supported method for updating libraries is via composer.

Marking this fixed for now, but I suspect that folks will have other issues in the future regarding the library. We'll take those on a case-by-case basis so others looking through the queue don't get confused if its not working for them.

  • japerry committed c958b45 on 8.x-1.x
    Issue #3151530 by japerry: Update to PHPMailer version 6.1.7.
    

Status: Fixed » Closed (fixed)

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

rdworianyn’s picture

For those of you that have tried uninstalling the module, reinstalling with composer, as suggested, and yet still got the same message, maybe give this a try. Restart your webserver, if you are using the PHP APCU module for cache. No matter how many times I uninstalled this module, rebuilt the Drupal cache, used Ludwig, etc...none of it actually worked until I did a restart of the webserver to clear APCU cache. Hope this helps someone!