因此,当我的用户注册时,我正在使用PHP中的PHPMailer库发送欢迎电子邮件,而这样做花了很长时间.
单击注册上的提交后,实际加载主页大约需要30-50秒.它基本上使页面处于重新加载状态超过30秒.
我使用的代码如下…
if ($config['user']['welcome_email_enabled'])
$autoLoader->getLibrary('mail')->sendWelcomeEmail($email, $username);
我的邮件库在这里.
<?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);
}
}
}
?>
因此,我首先要调用它们,然后在我想实际发送电子邮件时调用sendWelcomeEmail().
$mailer-> assignMailer(new PHPMailer());
和
$mailer->setupMail(
"********@gmail.com",
"**************",
"smtp.gmail.com");
为什么要花这么长时间?应该花这么长时间吗..
解决方法:
如您所见,在页面提交期间使用远程SMTP并不是一件好事-它通常非常慢(有时是故意进行greetdelay检查).解决方法是始终提交到本地(快速)邮件服务器,并让它处理等待,并处理诸如延迟传递之类的事情,而这是PHPMailer无法处理的.沿该路线行驶时,您还需要正确处理弹跳,因为您不会立即得到反馈.
您通常可以直接交货而已并不意味着这是一种可靠的方法.
要查看SMTP会话花费的时间很长,请设置$mailer-> SMTPDebug = 2;并观看输出(尽管不要在您的实时站点上执行该操作!).