Emails sent using PHP take too long

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 {

    // Needs to be set per object
    public $subject;
    public $message;
    public $to_name;
    public $to;

    private $mail; // This is the main mail object that'll be initialized 

    public function __construct() {

        // Need to create a PHPMailer object in the constuctor and return it for use in this class. 

        $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->Port = 587; // Turns out, I dont need this one. 
        $mail->SMTPAuth = true; // gmail requires this
        $mail->SMTPSecure = 'tls'; // gmail requires this

        $this->mail = $mail;


    }


    function send() {

        $mail = $this->mail; // The mail object 

        $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";
+4
source share
2 answers

SMTP - greetdelay/tarpit. RFC2821 4.5.3.2 5 . SMTP ( ), - SMTP -. Sendmail SMTP .

PHPMailer SMTP, , , , :

$mail->SMTPDebug = 2;
+6

, Gmail . Gmail, .

SMTP Gmail . , , - /, Gmail, .

, SMTP, .

smtp.gmail.com

, , Base64, . - Base64 .

. Linux. Linux , Cygwin ( Windows) OpenSSH Windows, Cygwin

+1

Source: https://habr.com/ru/post/1536341/


All Articles