I wrote a class in PHP that I use to send emails using a Gmail account. This class, in turn, uses the PHPMailer library. Configuring WAMP 2.4 on Windows Vista. Using the function microtime()in PHP, I see that it takes 5 to 6 seconds to send one mail. Is it normal for PHP to run a script that I should take up to 5-6 seconds to get one mail out. Here is the code for the class.
<?php
require_once("phpmailer/class.phpmailer.php");
require_once("phpmailer/class.smtp.php");
class Mailer {
public $subject;
public $message;
public $to_name;
public $to;
private $mail;
public function __construct() {
$mail = new PHPMailer();
$from_name = "bleh";
$from = "bleh@gmail.com";
$username = "bleh";
$password = "bleh";
$mail->FromName = $from_name;
$mail->From = $from;
$mail->Username = $username;
$mail->Password = $password;
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$this->mail = $mail;
}
function send() {
$mail = $this->mail;
$mail->Subject = $this->subject;
$mail->Body = $this->message;
$mail->AddAddress($this->to, $this->to_name);
$result = $mail->Send();
return $result;
}
}
?>
The code used to verify this is
$startTime = microtime(true);
require_once("mailer.php");
$mailer = new Mailer();
$mailer->subject = "Test";
$mailer->message = "Test";
$mailer->to_name = "My Name";
$mailer->to = "anemail@address";
$mailer->send();
echo "Time: " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";
source
share