I was following PHPMailer tutorial and some tutorials in Internet but I still can't make execution less than 2 second. On many website it says it shouldn't take more than 0.4s. I tried it from my local machine and from AWS machine. Execution time same.
class BatchMailer {
private static $mail;
private static $initialized = false;
private static function initialize() {
if (self::$initialized)
return;
self::$mail = new PHPMailer;
self::$mail->SMTPDebug = 2;
self::$mail->isSMTP();
self::$mail->Host = 'smtp.gmail.com';
self::$mail->Port = 587;
self::$mail->SMTPSecure = 'tls';
self::$mail->SMTPAuth = true;
self::$mail->Username = '***';
self::$mail->Password = '***';
self::$mail->SMTPKeepAlive = true;
self::$mail->setFrom('***@gmail.com', 'Title');
self::$mail->isHTML(true);
self::$mail->AltBody = 'Please use an HTML-enabled email client to view this message.';
self::$initialized = true;
}
public static function setSubject($subject) {
self::initialize();
self::$mail->Subject = $subject;
}
public static function setBody($body) {
self::initialize();
self::$mail->Body = stripslashes($body);
}
public static function sendTo() {
self::initialize();
self::$mail->clearAddresses();
$recipients = array(
'***@gmail.com' => 'Person One'
);
foreach($recipients as $email => $name) {
self::$mail->AddCC($email, $name);
}
self::$mail->send();
return;
}
static function test() {
self::setSubject('subject');
self::setBody('body');
self::sendTo();
}
}