title: PHP Mailer taking over 30 seconds to send a welcome email
body: <p>So I am using the PHPMailer library in PHP to send a welcome email when ever my users registered, and it takes so long to do this.</p>
  
  <p>It takes around 30 - 50 seconds to actually load the home page, after clicking submit on the registration. It basically puts the page in a reloading state for over 30 seconds.</p>
  
  <p>The code I use is below...</p>
  
  <pre><code>if ($config['user']['welcome_email_enabled'])
      $autoLoader-&gt;getLibrary('mail')-&gt;sendWelcomeEmail($email, $username);
  </code></pre>
  
  <p>And my mail library is here.</p>
  
  <pre><code>&lt;?php
  /**
   * MangoCMS, content management system.
   *
   * @info         Handles the mail functions.
   * @author       Liam Digital &lt;liamatzubbo@outlook.com&gt;
   * @version      1.0 BETA
   * @package      MangoCMS_Master
   *
   */
  
  defined("CAN_VIEW") or die('You do not have permission to view this file.');
  
  class mangoMail {
      private $phpMailer;
  
      public function assignMailer($phpMailer) {
          $this-&gt;phpMailer = $phpMailer;
      }
  
      public function setupMail($username, $password, $eHost) {
          if ($this-&gt;phpMailer == null)
              return;
  
          $this-&gt;phpMailer-&gt;isSMTP();
          $this-&gt;phpMailer-&gt;Host = $eHost;
          $this-&gt;phpMailer-&gt;SMTPAuth = true;
          $this-&gt;phpMailer-&gt;Username = $username;
          $this-&gt;phpMailer-&gt;Password = $password;
          $this-&gt;phpMailer-&gt;SMTPSecure = 'tls';
          $this-&gt;phpMailer-&gt;Port = 587;
      }
  
      public function sendMail() {
          if ($this-&gt;phpMailer == null)
              return;
  
          if (!$this-&gt;phpMailer-&gt;send()) {
              echo 'Message could not be sent.';
              echo 'Mailer Error: ' . $this-&gt;phpMailer-&gt;ErrorInfo;
              exit();
          }
          else {
              echo 'Email has been sent.';
          }
      }
  
      public function setFrom($from, $fromTitle) {
          $this-&gt;phpMailer-&gt;setFrom($from, $fromTitle);
      }
  
      public function addAddress($address) {
          $this-&gt;phpMailer-&gt;addAddress($address);
      }
  
      public function setSubject($subject) {
          $this-&gt;phpMailer-&gt;Subject = $subject;
      }
  
      public function setBody($body) {
          $this-&gt;phpMailer-&gt;Body = $body;
      }
  
      public function setAltBody($altBody) {
          $this-&gt;phpMailer-&gt;AltBody = $altBody;
      }
  
      public function setHTML($html) {
          $this-&gt;phpMailer-&gt;isHTML($html);
      }
  
      public function addReply($email, $name = '') {
          $this-&gt;phpMailer-&gt;addReplyTo($email, $name);
      }
  
      public function sendWelcomeEmail($email, $username) {
          global $config;
          $mailer = $this-&gt;phpMailer;
          $mailer-&gt;setFrom($config['website']['email'], $config['website']['owner']);
          $mailer-&gt;addAddress($email, $username);
          $mailer-&gt;addReplyTo($config['website']['email'], 'Reply Here');
          $mailer-&gt;isHTML(true);
          $mailer-&gt;Subject = 'Welcome to ' . $config['website']['name'] . ' (' . $config['website']['link'] . ')';
          $mailer-&gt;Body = '&lt;div style="background-color:#1a8cff;padding:24px;color:#fff;border-radius:3px;"&gt;
          &lt;h2&gt;Welcome to Zubbo ' . $username . '!&lt;/h2&gt;Thank you for joining the Zubbo community, we offer spectacular events, opportunities, and entertainment.&lt;br&gt;&lt;br&gt;When you join Zubbo you will recieve &lt;b&gt;250,000 credits&lt;/b&gt;, &lt;b&gt;100,000 duckets&lt;/b&gt;, and &lt;b&gt;5 diamonds&lt;/b&gt;. One way to earn more is by being online and active, the more you are active the more you will earn, other ways are competitions, events, and games :)&lt;br&gt;&lt;br&gt;We strive to keep the community safe and secure, so if you have any questions or concerns or have found a bug please reply to this email or contact us using in-game support.&lt;br&gt;&lt;br&gt;Thank you for joining Zubbo Hotel!&lt;br&gt;- Zubbo Staff Team
          &lt;/div&gt;';
          $mailer-&gt;AltBody = 'Here is a alt body...';
          if (!$mailer-&gt;send()) {
              exit('FAILED TO SEND WELCOME EMAIL!! ' . $mailer-&gt;ErrorInfo);
          }
      }
  }
  ?&gt;
  </code></pre>
  
  <p>So I call these to start with, then the sendWelcomeEmail() when I want to actually send the email.</p>
  
  <p>$mailer->assignMailer(new PHPMailer());</p>
  
  <p>and </p>
  
  <pre><code>$mailer-&gt;setupMail(
      "********@gmail.com",
      "**************",
      "smtp.gmail.com");
  </code></pre>
  
  <p>Why is it taking so long? Should it be taking this long..</p>