PHP Mailer levando mais de 30 segundos para enviar um email de boas-vindas

Portanto, estou usando a biblioteca PHPMailer no PHP para enviar um email de boas-vindas sempre que meus usuários se registrarem, e isso leva muito tempo.

Demora de 30 a 50 segundos para carregar a página inicial, depois de clicar em enviar no registro. Basicamente, coloca a página em um estado de recarregamento por mais de 30 segundos.

O código que eu uso está abaixo ...

if ($config['user']['welcome_email_enabled'])
    $autoLoader->getLibrary('mail')->sendWelcomeEmail($email, $username);

E minha biblioteca de correio está aqui.

<?php
/**
 * MangoCMS, content management system.
 *
 * @info         Handles the mail functions.
 * @author       Liam Digital <[email protected]>
 * @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->phpMailer = $phpMailer;
    }

    public function setupMail($username, $password, $eHost) {
        if ($this->phpMailer == null)
            return;

        $this->phpMailer->isSMTP();
        $this->phpMailer->Host = $eHost;
        $this->phpMailer->SMTPAuth = true;
        $this->phpMailer->Username = $username;
        $this->phpMailer->Password = $password;
        $this->phpMailer->SMTPSecure = 'tls';
        $this->phpMailer->Port = 587;
    }

    public function sendMail() {
        if ($this->phpMailer == null)
            return;

        if (!$this->phpMailer->send()) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $this->phpMailer->ErrorInfo;
            exit();
        }
        else {
            echo 'Email has been sent.';
        }
    }

    public function setFrom($from, $fromTitle) {
        $this->phpMailer->setFrom($from, $fromTitle);
    }

    public function addAddress($address) {
        $this->phpMailer->addAddress($address);
    }

    public function setSubject($subject) {
        $this->phpMailer->Subject = $subject;
    }

    public function setBody($body) {
        $this->phpMailer->Body = $body;
    }

    public function setAltBody($altBody) {
        $this->phpMailer->AltBody = $altBody;
    }

    public function setHTML($html) {
        $this->phpMailer->isHTML($html);
    }

    public function addReply($email, $name = '') {
        $this->phpMailer->addReplyTo($email, $name);
    }

    public function sendWelcomeEmail($email, $username) {
        global $config;
        $mailer = $this->phpMailer;
        $mailer->setFrom($config['website']['email'], $config['website']['owner']);
        $mailer->addAddress($email, $username);
        $mailer->addReplyTo($config['website']['email'], 'Reply Here');
        $mailer->isHTML(true);
        $mailer->Subject = 'Welcome to ' . $config['website']['name'] . ' (' . $config['website']['link'] . ')';
        $mailer->Body = '<div style="background-color:#1a8cff;padding:24px;color:#fff;border-radius:3px;">
        <h2>Welcome to Zubbo ' . $username . '!</h2>Thank you for joining the Zubbo community, we offer spectacular events, opportunities, and entertainment.<br><br>When you join Zubbo you will recieve <b>250,000 credits</b>, <b>100,000 duckets</b>, and <b>5 diamonds</b>. 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 :)<br><br>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.<br><br>Thank you for joining Zubbo Hotel!<br>- Zubbo Staff Team
        </div>';
        $mailer->AltBody = 'Here is a alt body...';
        if (!$mailer->send()) {
            exit('FAILED TO SEND WELCOME EMAIL!! ' . $mailer->ErrorInfo);
        }
    }
}
?>

Então, eu os chamo para começar, depois o sendWelcomeEmail () quando realmente quero enviar o email.

$ mailer-> assignMailer (novo PHPMailer ());

e

$mailer->setupMail(
    "********@gmail.com",
    "**************",
    "smtp.gmail.com");

Por que demora tanto tempo? Deve demorar tanto ..

questionAnswers(2)

yourAnswerToTheQuestion