Hi, the PHPmailer is very slow when i use it in server linux
Your code? Debug output?
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
-----------------------------------
$boitea = explode ('/',$boites[$i]);
$boite = $boitea[0];
$pass = $boitea[1];
$froms = explode ('@',$boite);
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = $boite;
//Password to use for SMTP authentication
$mail->Password = $pass;
if (isset($_POST['from_name']))
{
$from_name = $_POST['from_name'];
}
else {
$from_name = $froms[0];
}
$mail->setFrom($boite, $from_name);
$mail->addReplyTo($boite, $from_name);
$datas = '';
$select = "select email from emails offset $offset limit $limit";
$res_data = pg_query($connection $select);
while ($object_data = pg_fetch_array($res_data))
{
$email = trim($object_data[0]) ;
$emails = explode('@',$email);
$from_name_to = $emails[0];
$mail->addAddress($email, $from_name_to);
}
if ($mail->send()) {
echo "Message sent!";
} else {
echo "Mail Error: " . $mail->ErrorInfo;
}
$mail->ClearAddresses();
Learn how to use source formatting on GitHub.
Since you have SMTPDebug = 2, you should be able to watch the output and see exactly when it is being slow. SMTP is not a fast protocol, and often includes deliberate delays. If it's a big problem, decouple your sending and send asynchronously.
PHPMailer has been sending emails fast and conveniently, even with attatched documents in my local server (Using Microsoft IIS), but when my app goes live, I can't send emails. And am pretty sure my net speed is not the issue.
// send email without attachment
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'mypass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('[email protected]', 'Kimmy Soft Inc.');
$mail->addReplyTo($email, $fname);
$recipients = array('[email protected]');
foreach($recipients as $to ){
$mail->addAddress($to); // Add a recipient
}
//$mail->addCC('[email protected]');
//$mail->addBCC('[email protected]');
$mail->isHTML(true); // Set email format to HTML
$bodyContent = ""
$mail->Subject = 'Employee Leave Application.';
$mail->Body = $bodyContent;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
// redirect to previous page with an error message
header("Location: ../content/apply_leave.php?ceoMailNotSent");
} else {
echo "Email sent successfully";
}
@DannySofftie How about you actually read what this closed ticket says, do what it suggests and set SMTPDebug = 2 so that you can see what's taking the time, before posting unnecessarily here?
@Synchro Is it possible to send mail asynchronously and not wait to finish? How?
It's not async, but if you send via SMTP to localhost (and run your own local mail server), it is very fast; it's remote servers, latency, and bandwidth that are likely to slow you down. See the performance info in the wiki.
2019-05-28 20:26:24 SERVER -> CLIENT: 220 mail.mine.com ESMTP Postfix ###
2019-05-28 20:26:24 CLIENT -> SERVER: EHLO 192.168.1.152
2019-05-28 20:26:24 SERVER -> CLIENT: 250-mail.itbstaffing.com250-PIPELINING250-SIZE 10240000250-VRFY250-ETRN250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2019-05-28 20:26:24 CLIENT -> SERVER: AUTH LOGIN
2019-05-28 20:26:24 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-05-28 20:26:24 CLIENT -> SERVER:
2019-05-28 20:26:24 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-05-28 20:26:24 CLIENT -> SERVER:
2019-05-28 20:26:25 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2019-05-28 20:26:25 CLIENT -> SERVER: MAIL FROM:mine@mail.com
2019-05-28 20:26:25 SERVER -> CLIENT: 250 2.1.0 Ok
2019-05-28 20:26:25 CLIENT -> SERVER: RCPT TO:you@mail.com
2019-05-28 20:26:25 SERVER -> CLIENT: 250 2.1.5 Ok
2019-05-28 20:26:25 CLIENT -> SERVER: DATA
2019-05-28 20:26:25 SERVER -> CLIENT: 354 End data with
2019-05-28 20:26:25 CLIENT -> SERVER: Date: Tue, 28 May 2019 22:26:23 +0200
2019-05-28 20:26:25 CLIENT -> SERVER: To: [email protected]
2019-05-28 20:26:25 CLIENT -> SERVER: From: Joy mine@mail.com
2019-05-28 20:26:25 CLIENT -> SERVER: Reply-To: [email protected]
2019-05-28 20:26:25 CLIENT -> SERVER: Subject: ###
2019-05-28 20:26:25 CLIENT -> SERVER: Message-ID:
2019-05-28 20:26:25 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)
2019-05-28 20:26:25 CLIENT -> SERVER: MIME-Version: 1.0
2019-05-28 20:26:25 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER: Dear Name ;
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER:
2019-05-28 20:26:25 CLIENT -> SERVER: .
2019-05-28 20:26:26 SERVER -> CLIENT: 250 2.0.0 Ok: queued as 90DC1B02FC
2019-05-28 20:26:26 CLIENT -> SERVER: QUIT
2019-05-28 20:26:26 SERVER -> CLIENT: 221 2.0.0 Bye
I am using bulk Email atleast (100 Members) for sending email at a time.. one email its taking 3 seconds to send mail.. if i am sending in bulk its taking too much time.. how to reduce the time cost.. help me..
My internet is not slow... Email going successfully to recipient.. but its time taking.. Any Idea... or share me some related links to reduce the time.. i will be thankfull to you..
<?php
require 'vendor/autoload.php';
$mail = new PHPMailer(true);
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
// i am using outlook
$mail->Host = 'mine.mail.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = $_SESSION['suser_email'];
$mail->Password = $pass;
$mail->setFrom($mail->Username, $pseudo);
$mail->isHTML(true);
$address = explode(',', $add);
if($cc == Null){
}else{
$mail->addBCC($cc);
}
foreach($address as $item){
$data=explode("|",$item);
$mail->addAddress($data[0]);
$mail->addReplyTo($_SESSION['suser_email']);
$mail->Body = 'Dear '.$data[1].' ;'.$msg;
$mail->Subject = $sub;
if(!$mail->send()) {
$gen->setNotice("Hey! Error occured !... One or More Email Id is not valid... Can not send email... Please deselect invalid email and then send again.", "error");
$gen->redirect($gen->getmyurl());
} else {
$gen->setNotice("Hey! ".$full_name.", Email Sent successfully.", "success");
$gen->redirect($gen->getmyurl());
}
$mail->ClearAllRecipients();
}
?>
Above is my code
As this thread says, there is an article in the wiki that tells you how to maximise performance when sending to lists. Using this advice (and a very good mail server) I can create and send about 300 messages per second.
Also, don't disable certificate verification unless you have an explicit, known reason to do so (and no, "to make it work" is not good enough).
2019-05-29 19:01:12 SERVER -> CLIENT: 220 mail.your.com ESMTP Postfix
2019-05-29 19:01:12 CLIENT -> SERVER: EHLO 192.168.1.152
2019-05-29 19:01:12 SERVER -> CLIENT: 250-mail.itbtalent.com250-PIPELINING250-SIZE 15360000250-VRFY250-ETRN250-STARTTLS250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2019-05-29 19:01:12 CLIENT -> SERVER: STARTTLS
2019-05-29 19:01:13 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2019-05-29 19:01:13 CLIENT -> SERVER: EHLO 192.168.1.152
2019-05-29 19:01:14 SERVER -> CLIENT: 250-mail.itbtalent.com250-PIPELINING250-SIZE 15360000250-VRFY250-ETRN250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-ENHANCEDSTATUSCODES250-8BITMIME250 DSN
2019-05-29 19:01:14 CLIENT -> SERVER: AUTH LOGIN
2019-05-29 19:01:14 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2019-05-29 19:01:14 CLIENT -> SERVER: <credentials hidden>
2019-05-29 19:01:14 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2019-05-29 19:01:14 CLIENT -> SERVER: <credentials hidden>
2019-05-29 19:01:14 SERVER -> CLIENT: 235 2.7.0 Authentication successful
2019-05-29 19:01:14 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-05-29 19:01:15 SERVER -> CLIENT: 250 2.1.0 Ok
2019-05-29 19:01:15 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-05-29 19:01:15 SERVER -> CLIENT: 250 2.1.5 Ok
2019-05-29 19:01:15 CLIENT -> SERVER: DATA
2019-05-29 19:01:15 SERVER -> CLIENT: 354 End data with <CR><LF>.<CR><LF>
2019-05-29 19:01:15 CLIENT -> SERVER: Date: Wed, 29 May 2019 19:01:12 +0000
2019-05-29 19:01:15 CLIENT -> SERVER: To: name <[email protected]>
2019-05-29 19:01:15 CLIENT -> SERVER: From: mine <[email protected]>
2019-05-29 19:01:15 CLIENT -> SERVER: Reply-To: [email protected]
2019-05-29 19:01:15 CLIENT -> SERVER: Subject: hello all
2019-05-29 19:01:15 CLIENT -> SERVER: Message-ID: <[email protected]>
2019-05-29 19:01:15 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)
2019-05-29 19:01:15 CLIENT -> SERVER: MIME-Version: 1.0
2019-05-29 19:01:15 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-05-29 19:01:15 CLIENT -> SERVER:
2019-05-29 19:01:15 CLIENT -> SERVER: Dear name1 ;<html>
2019-05-29 19:01:15 CLIENT -> SERVER: <head>
2019-05-29 19:01:15 CLIENT -> SERVER: <title></title>
2019-05-29 19:01:15 CLIENT -> SERVER: </head>
2019-05-29 19:01:15 CLIENT -> SERVER: <body>
2019-05-29 19:01:15 CLIENT -> SERVER: <p>hello all</p>
2019-05-29 19:01:15 CLIENT -> SERVER: </body>
2019-05-29 19:01:15 CLIENT -> SERVER: </html>
2019-05-29 19:01:15 CLIENT -> SERVER:
2019-05-29 19:01:15 CLIENT -> SERVER: .
2019-05-29 19:01:16 SERVER -> CLIENT: 250 2.0.0 Ok: queued as DB97B2029CBF8
2019-05-29 19:01:16 CLIENT -> SERVER: RSET
2019-05-29 19:01:17 SERVER -> CLIENT: 250 2.0.0 Ok
2019-05-29 19:01:17 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-05-29 19:01:17 SERVER -> CLIENT: 250 2.1.0 Ok
2019-05-29 19:01:17 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-05-29 19:01:17 SERVER -> CLIENT: 250 2.1.5 Ok
2019-05-29 19:01:17 CLIENT -> SERVER: DATA
2019-05-29 19:01:17 SERVER -> CLIENT: 354 End data with <CR><LF>.<CR><LF>
2019-05-29 19:01:17 CLIENT -> SERVER: Date: Wed, 29 May 2019 19:01:17 +0000
2019-05-29 19:01:17 CLIENT -> SERVER: To: name2 <[email protected]>
2019-05-29 19:01:17 CLIENT -> SERVER: From: mine <[email protected]>
2019-05-29 19:01:17 CLIENT -> SERVER: Reply-To: [email protected]
2019-05-29 19:01:17 CLIENT -> SERVER: Subject: hello all
2019-05-29 19:01:17 CLIENT -> SERVER: Message-ID: <[email protected]>
2019-05-29 19:01:17 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)
2019-05-29 19:01:17 CLIENT -> SERVER: MIME-Version: 1.0
2019-05-29 19:01:17 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-05-29 19:01:17 CLIENT -> SERVER:
2019-05-29 19:01:17 CLIENT -> SERVER: Dear name3 ;<html>
2019-05-29 19:01:17 CLIENT -> SERVER: <head>
2019-05-29 19:01:17 CLIENT -> SERVER: <title></title>
2019-05-29 19:01:17 CLIENT -> SERVER: </head>
2019-05-29 19:01:17 CLIENT -> SERVER: <body>
2019-05-29 19:01:17 CLIENT -> SERVER: <p>hello all</p>
2019-05-29 19:01:17 CLIENT -> SERVER: </body>
2019-05-29 19:01:17 CLIENT -> SERVER: </html>
2019-05-29 19:01:17 CLIENT -> SERVER:
2019-05-29 19:01:17 CLIENT -> SERVER: .
2019-05-29 19:01:18 SERVER -> CLIENT: 250 2.0.0 Ok: queued as EE55F200FA5C0
2019-05-29 19:01:18 CLIENT -> SERVER: RSET
2019-05-29 19:01:18 SERVER -> CLIENT: 250 2.0.0 Ok
2019-05-29 19:01:18 CLIENT -> SERVER: MAIL FROM:<[email protected]>
2019-05-29 19:01:18 SERVER -> CLIENT: 250 2.1.0 Ok
2019-05-29 19:01:18 CLIENT -> SERVER: RCPT TO:<[email protected]>
2019-05-29 19:01:19 SERVER -> CLIENT: 250 2.1.5 Ok
2019-05-29 19:01:19 CLIENT -> SERVER: DATA
2019-05-29 19:01:19 SERVER -> CLIENT: 354 End data with <CR><LF>.<CR><LF>
2019-05-29 19:01:19 CLIENT -> SERVER: Date: Wed, 29 May 2019 19:01:18 +0000
2019-05-29 19:01:19 CLIENT -> SERVER: To: name3 <[email protected]>
2019-05-29 19:01:19 CLIENT -> SERVER: From: mine <[email protected]>
2019-05-29 19:01:19 CLIENT -> SERVER: Reply-To: [email protected]
2019-05-29 19:01:19 CLIENT -> SERVER: Subject: hello all
2019-05-29 19:01:19 CLIENT -> SERVER: Message-ID: <[email protected]>
2019-05-29 19:01:19 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.7 (https://github.com/PHPMailer/PHPMailer)
2019-05-29 19:01:19 CLIENT -> SERVER: MIME-Version: 1.0
2019-05-29 19:01:19 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
2019-05-29 19:01:19 CLIENT -> SERVER:
2019-05-29 19:01:19 CLIENT -> SERVER: Dear name3 ;<html>
2019-05-29 19:01:19 CLIENT -> SERVER: <head>
2019-05-29 19:01:19 CLIENT -> SERVER: <title></title>
2019-05-29 19:01:19 CLIENT -> SERVER: </head>
2019-05-29 19:01:19 CLIENT -> SERVER: <body>
2019-05-29 19:01:19 CLIENT -> SERVER: <p>hello all</p>
2019-05-29 19:01:19 CLIENT -> SERVER: </body>
2019-05-29 19:01:19 CLIENT -> SERVER: </html>
2019-05-29 19:01:19 CLIENT -> SERVER:
2019-05-29 19:01:19 CLIENT -> SERVER: .
2019-05-29 19:01:22 SERVER -> CLIENT: 250 2.0.0 Ok: queued as 81214200FA5C0
2019-05-29 19:01:22 CLIENT -> SERVER: RSET
2019-05-29 19:01:22 SERVER -> CLIENT: 250 2.0.0 Ok
I am sending bulk email (atleast 30 emails) at a time.. but its taking too much time . The above code is for 3 email.. when i debug it shows me the success message, but its time consuming to send 3 emails.. i have to send 30emails at a time so according to it , its taking around 3 minutes.. any idea to reduce the time cost
Also , Every 1 email sent its showing the number of times the same message body repeating to number of recipient . I want to reduce the time. Help me its Urgent..
Two ways to improve performance (from your script's point of view).
Instead of using your ISP's mail server directly (because it seems to be very slow), run a mail server (postfix is good) on your own server and configure it to relay through your ISP's server. Don't ask me how to do that - there are plenty of docs & resources to help you. A fast local server should be able to do exactly what your ISPs server does, but in a fraction of the time.
If you're sending during a page load, don't. Save some instructions in your database that can be picked up by a separate process running from a queue or a cron job and have that do the slow sending part without making your page load wait for it. Again, I don't have any particular instructions for how to do this, but there are many resources that can help you if you search.
Has someone found a solution for the @ghoshashish 's issue with slow sending? I have VERY SAME issue in my case and I don't know how to help myself. Thank you.
The best way to help yourself is to read the comments in this issue and the performance article that's linked. @ghoshashish last problem:
the number of times the same message body repeating to number of recipient
suggests to me that he's probably not calling clearAddresses() inside a sending loop, which can cause a message explosion, and has not read the notes or the example code for sending to lists.
Most helpful comment
Learn how to use source formatting on GitHub.
Since you have
SMTPDebug = 2, you should be able to watch the output and see exactly when it is being slow. SMTP is not a fast protocol, and often includes deliberate delays. If it's a big problem, decouple your sending and send asynchronously.