Modifying Vanilla 2.3.1 to use PHPMailer 5.2.24
Hi everyone,
My site cannot send emails since upgrading to Vanilla 2.3.1, so I tried various fixes and the latest suggestion was to upgrade the PHPMailer.
Short question:
Can I modify Vanilla 2.3.1 to work with the latest version of PHPMailer (5.2.24)?
Long question:
Since I upgraded my production site (Linux, Apache) from Vanilla 2.2.1 on PHP 5.5 to Vanilla 2.3.1 on PHP 7.0, my site cannot send emails - failing with the message "SMTP Error: Could not connect to SMTP host."
After trying to fix the issue for a while, I asked a question on Stack Overflow and was told that the PHPMailer version is too old and I should get the latest version.
So I checked the version, it seems that Vanilla 2.3.1 is using PHPMailer 5.1. I downloaded the latest version (5.2.24) and replaced the files in \library\vendors\phpmailer
with the new version.
Now when I try to send email, I get this error:
Whoops! There was an error. FATAL ERROR IN: Gdn_Email.send(); "Call to undefined method PHPMailer::throwExceptions()" LOCATION: (...)/www/forum/library/core/class.email.php
355: // We've skipped all recipients.
356: return true;
357: }
358:
359: $this->PhpMailer->throwExceptions(true);
360: if (!$this->PhpMailer->send()) {
361: throw new Exception($this->PhpMailer->ErrorInfo);
362: }
363:
BACKTRACE: [(...)/www/forum/applications/dashboard/controllers/class.settingscontroller.php 781] Gdn_Email->send(); [(...)/www/forum/library/core/class.dispatcher.php 326] SettingsController->emailTest(); [(...)/www/forum/index.php 44] Gdn_Dispatcher->dispatch();
Clearly there is more work I need to do if I'm gonna get this working... Looks like the code has to be updated but I'm not knowledgeable about PHP.
I can see that Vanilla 2.4 beta 1 is using PHPMailer 5.2.22, however I would like to stick with the stable release for now.
So my question is, can I modify Vanilla 2.3.1 to work with PHPMailer 5.2.24 (or even 5.2.22)? I know modifying core code is a bad idea, but after trying to troubleshoot this issue for 2 weeks I am desperate. If I can't get 2.3.1 to send emails I'll have to revert to 2.2.1, email is critical for me... Any help is greatly appreciated! And thank you Vanilla team for such a great platform!
If anyone would like more details on what I've tried so far, please see the Stack Overflow question:
https://stackoverflow.com/questions/45406895/vanilla-forum-smtp-error-could-not-connect-to-smtp-host
Best Answer
-
R_J Admin
Short answer: yes
Long answer: you can try to find out what have been done during the update process by working your way through the pull request.
I don't think you would be able to simply "see" what is needed but you would have to try a lot and you would need testing and debugging.
I cannot imagine that someone without much knowledge of php is able to do so.But nevertheless you can try!
Look at a) the error message above "Call to undefined method PHPMailer::throwExceptions()" and b) the file VanillaMailer in the PR above.
You see that there is a method in the file which looks exactly like the missing method. That might be helpful...
In the pull request, there are 9 files changes: the composer files and the files in library/vendors/phpmailer shouldn't be important here. I would guess that all changes in Vanilla has taken place in the other 3 files. 3 files doesn't sound scary at all.
The 3 files left are:
applications/dashboard/models/class.activitymodel.php
library/Vanilla/VanillaMailer.php
library/core/class.email.phpBefore we proceed: backup them!
There are two approaches you could take:
Replace and see what is happening!
Download Vanilla 2.4 beta, replace both files in the library subfolders, but do the changes to the ActivityModel manually.
Test, test, test...
Reproduce the pull request
Change the above three files like they have been changed in the pull request. Be sure not to miss something, only start testing after you are sure you have changed all three files
Test, test, test...
I'm quite optimistic that this should work. Please report back.
5
Answers
Short answer: yes
Long answer: you can try to find out what have been done during the update process by working your way through the pull request.
I don't think you would be able to simply "see" what is needed but you would have to try a lot and you would need testing and debugging.
I cannot imagine that someone without much knowledge of php is able to do so.
But nevertheless you can try!
Look at a) the error message above "Call to undefined method PHPMailer::throwExceptions()" and b) the file VanillaMailer in the PR above.
You see that there is a method in the file which looks exactly like the missing method. That might be helpful...
In the pull request, there are 9 files changes: the composer files and the files in library/vendors/phpmailer shouldn't be important here. I would guess that all changes in Vanilla has taken place in the other 3 files. 3 files doesn't sound scary at all.
The 3 files left are:
applications/dashboard/models/class.activitymodel.php
library/Vanilla/VanillaMailer.php
library/core/class.email.php
Before we proceed: backup them!
There are two approaches you could take:
Replace and see what is happening!
Download Vanilla 2.4 beta, replace both files in the library subfolders, but do the changes to the ActivityModel manually.
Test, test, test...
Reproduce the pull request
Change the above three files like they have been changed in the pull request. Be sure not to miss something, only start testing after you are sure you have changed all three files
Test, test, test...
I'm quite optimistic that this should work. Please report back.
@R_J
Hi RJ, thank you so much for the detailed answer! I really appreciate your time and effort!
I followed your instructions and the first approach, here is what I did:
V2.3.1\library\vendors\phpmailer
with PHPMailer 5.2.22V2.3.1\library\core\class.email.php
withV2.4b\library\core\class.email.php
V2.3.1\library
(since it doesn't exist in 2.3.1)V2.4b\library\Vanilla\VanillaMailer.php
toV2.3.1\library\Vanilla\VanillaMailer.php
V2.3.1\applications\dashboard\models\class.activitymodel.php
in 3 places following the diffNow I get this error:
I contemplated the error a bit but can't seem to figure out what's wrong, I double checked
V2.3.1\library\Vanilla\VanillaMailer.php
exists...Would you have any suggestion what I should do here? Again thank you for your kindness!
I know what the problem is, but I'm not sure I can help solving it. The class is not autoloaded and it needs to have the correct namespace.
Namespaces are still some kind of a mystery to me.
If it is not found automatically in the "library/Vanilla" folder, include it manually. Try adding
include_once(PATH_LIBRARY.'/Vanilla/VanillaMailer.php');
above theclass Gdn_Email...
line in the file library/core/class.email.phpAnd now either of the following might happen:
a) everything works great
b) you get a different error message then
c) nothing changes
a) would be best, b) might be solved but if it is c), I wouldn't be able to help.
@R_J
It's a)! I added the include line and now it's working perfectly!! Finally! (feel like crying)
Thank you SO much RJ, you're awesome!! Really grateful for your help!
I feel relieved, too