HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

SMTP outgoing email not working and how I debugged and fixed it

Hi everyone,

For the record, I'm a total PHP newbie, but managed to fix my problem and want to share so that it may be incorporated in future releases.

I managed to isolate and fix the problem using the following PHP script to exercise the PhpMailer class used by Vanilla:

<?php
   //set absolute path of phpmailer in forum
   require('forum/vendor/phpmailer/phpmailer/class.phpmailer.php'); 
   require('forum/vendor/phpmailer/phpmailer/class.smtp.php');
   //set the following
   $SupportName = 'Forum';
   $SupportAddress = 'forum@mysite.com';
   $SmtpHost = 'smtp.mysite.com';
   $SmtpUser = 'forum@mysite.com';
   $SmtpPassword = 'Secret';
   $SmtpPort = 587;
   $SmtpSecurity =''; //blank or tls/ssl
   //set recipient details 
   $RecipientEmail = 'test@mysite.com';
   $RecipientName = 'User';
  // do not edit bellow
   $PhpMailer = new PHPMailer(TRUE);
   $PhpMailer->CharSet = 'utf-8';
   $PhpMailer->SingleTo = FALSE;
   $PhpMailer->IsSMTP();
   $PhpMailer->Host = $SmtpHost;
   $PhpMailer->Port = $SmtpPort;
   $PhpMailer->SMTPSecure = $SmtpSecurity;
   $PhpMailer->SMTPAutoTLS = false;
   $PhpMailer->SMTPAuth = true;
   $PhpMailer->Username = $SmtpUser;
   $PhpMailer->Password = $SmtpPassword;
   $PhpMailer->SetFrom($SupportAddress, $SupportName, FALSE);
   $PhpMailer->AddAddress($RecipientEmail, $RecipientName);
   $PhpMailer->Subject = 'toets boodskap';
   $PhpMailer->Body = 'Dit werk al weer!';
   if (!$PhpMailer->Send()) {
      throw new Exception($PhpMailer->ErrorInfo);
   }

I had to explicitely add the line "$PhpMailer->SMTPAutoTLS = false;". To apply the fix, edit "library/core/class.email.php" and add the line "$this->PhpMailer->$SMTPAutoTLS = false;" line 343 in "public function send($eventName = '')"

            $this->PhpMailer->Host = $smtpHost;
            $this->PhpMailer->Port = $smtpPort;
            $this->PhpMailer->SMTPSecure = c('Garden.Email.SmtpSecurity', '');
            $this->PhpMailer->Username = $username = c('Garden.Email.SmtpUser', '');
            $this->PhpMailer->Password = $password = c('Garden.Email.SmtpPassword', '');
            $this->PhpMailer->$SMTPAutoTLS = false;
            if (!empty($username)) {
                $this->PhpMailer->SMTPAuth = true;
            }

Regards,
Pieter

Comments

Sign In or Register to comment.