Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

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/

355: // We've skipped all recipients.
356: return true;
357: }
359: $this->PhpMailer->throwExceptions(true);
360: if (!$this->PhpMailer->send()) {
361: throw new Exception($this->PhpMailer->ErrorInfo);
362: }

[(...)/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:

Best Answer


  • Options

    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:

    1. Replace V2.3.1\library\vendors\phpmailer with PHPMailer 5.2.22
    2. Replace V2.3.1\library\core\ with V2.4b\library\core\
    3. Create empty Vanilla folder under V2.3.1\library (since it doesn't exist in 2.3.1)
    4. Copy V2.4b\library\Vanilla\VanillaMailer.php to V2.3.1\library\Vanilla\VanillaMailer.php
    5. Modify V2.3.1\applications\dashboard\models\class.activitymodel.php in 3 places following the diff

    Now I get this error:

    Whoops! There was an error.
    FATAL ERROR IN: Gdn_Email.__construct();
    "Class 'Vanilla\VanillaMailer' not found"
    LOCATION: (...)/www/forum/library/core/

    40: /**
    41: * Constructor.
    42: */
    43: function __construct() {

    44: $this->PhpMailer = new \Vanilla\VanillaMailer();

    45: $this->PhpMailer->CharSet = 'utf-8';
    46: $this->PhpMailer->SingleTo = c('Garden.Email.SingleTo', false);
    47: $this->PhpMailer->Hostname = c('Garden.Email.Hostname', '');
    48: $this->PhpMailer->Encoding = 'quoted-printable';

    [(...)/www/forum/applications/dashboard/controllers/class.settingscontroller.php 709] Gdn_Email->__construct();
    [(...)/www/forum/applications/dashboard/controllers/class.settingscontroller.php 778] SettingsController->getTestEmail();
    [(...)/www/forum/library/core/class.dispatcher.php 326] SettingsController->emailTest();
    [(...)/www/forum/index.php 44] Gdn_Dispatcher->dispatch();

    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!

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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 the class Gdn_Email... line in the file library/core/

    And 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.

  • Options

    It's a)! I added the include line and now it's working perfectly!! :D Finally! (feel like crying)

    Thank you SO much RJ, you're awesome!! Really grateful for your help! :D

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    I feel relieved, too =)

Sign In or Register to comment.