sruupl / batflat

Lightweight, fast and easy CMS for free. Bootstrap ready. https://batflat.org
MIT License
134 stars 54 forks source link

Phpmailer in contact form #46

Closed thomascenni closed 5 years ago

thomascenni commented 5 years ago

Hi, I have installed PhpMailer in the project directory with composer. So I have a "vendor" folder with inside the autoload.php and the phpmailer folder. But the contact form is not working and I still get the message "Sorry, I can't find PHPMailer class. Please, execute composer require phpmailer/phpmailer in your project terminal." Thanks for helping.

michu2k commented 5 years ago

Hi Open composer.json file and change phpmailer version to 5.2.26, then run composer update

Edit: This is a potential solution for composer 6+ :

Open inc/modules/contact/view/admin/settings.html Change : {if: !class_exists("PHPMailer")} To:
{if: !class_exists("PHPMailer\PHPMailer\PHPMailer")}

Open inc/modules/contact/Site.php Change: $mail = new \PHPMailer(true); To: $mail = new \PHPMailer\PHPMailer\PHPMailer(true);

Change: catch (\phpmailerException $e) { To: catch (\Exception $e) {

Edit2:

Change: class_exists('PHPMailer') To: class_exists('PHPMailer\PHPMailer\PHPMailer')

If you can, please try second solution and let me know that it works for sure

thomascenni commented 5 years ago

Hi, I changed PHPMailer to version 5.2.26 and everything works fine, thanks.

Since PHPMailer 6 breaks backward compatibility mainly due to the use of a namespace, wouldn't be better to release an update of the Contact module ? All users trying to install PHPMailer via Composer will get the latest version 6+. Official PHPMailer documentation says that "PHPMailer 5.2 (which is compatible with PHP 5.0 - 7.0) is no longer being supported for feature update".

michu2k commented 5 years ago

Hi Ofc i know that we should update the contact module, thats why i give you second solution, but i need more tests on this before i decide to push new changes.

thomascenni commented 5 years ago

Hi @michu2k I did a test with phpmailer v6.0.5 and the modifications proposed above, the mail was successfully sent. I used Mailgun as SMTP server.

michu2k commented 5 years ago

@thomascenni Thanks for your feedback !