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.
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.
The code I use is below...
if ($config['user']['welcome_email_enabled'])
$autoLoader->getLibrary('mail')->sendWelcomeEmail($email, $username);
And my mail library is here.
<?php
/**
* MangoCMS, content management system.
*
* @info Handles the mail functions.
* @author Liam Digital <liamatzubbo@outlook.com>
* @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);
}
}
}
?>
So I call these to start with, then the sendWelcomeEmail() when I want to actually send the email.
$mailer->assignMailer(new PHPMailer());
and
$mailer->setupMail(
"********@gmail.com",
"**************",
"smtp.gmail.com");
Why is it taking so long? Should it be taking this long..