[[+content_image]]
A
A
Anastasia2021-01-08 04:01:42
Email
Anastasia, 2021-01-08 04:01:42

How and with what speed should emails be sent?

I'm trying to organize mailing of letters (not spam) to users. For each recipient, an original letter is generated (such as a special offer). How I did: I
collected an array

[["email", "ФИО", "данные"],
["email", "ФИО", "данные"]
...
]

And went through the for loop through the array, sending letters using phpmailer. That is, in each iteration it was:
$mail = new PHPMailer\PHPMailer\PHPMailer();
try {
    $mail->isSMTP();   
    $mail->CharSet = "UTF-8";
...

For the test, I sent it to 10 recipients (to myself). All letters have been delivered
spoiler
This is not so important, but in fact, on the very first sending (I sent several times), one letter was not delivered and I don’t know why, although the logs were all success, but the letter was not received on one of the mails. When you repeat the operation, all recipients have already received a letter. It's strange


But there's a problem. I had a timer: so it took 13 seconds for 10 letters ... This is more than 1 second per person. And it's very long. If there are 40k users, then such a mailing will take more than 12 hours. What am I doing wrong? $t = microtime(1);e(microtime(1) - $t);

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
C
CityCat4, 2021-01-08
@CityCat4

Please tell me what am I doing wrong?

Idea. If you send via Yandex, for example, then after some, but less than a hundred, you will simply be slowed down and banned for sending spam (this is not spam for you - but for Yandex (and for me) sending 40k addresses is a real spam.For such mailings, they usually take either their own servers or paid services.Both work the same way - they take all your 40k letters into the queue and begin to slowly send it out.SMTP is not a channel for transmitting business information, you know? sending letters is allowed up to 5 days, you know? Therefore, 12 hours for mailing is still nonsense.
Well, for regular mailings, mailing list managers are generally installed - you send him one letter, and he himself will sort out the list.

G
galaxy, 2021-01-08
@galaxy

If you send via an external SMTP server (via yandex or mail.ru, for example), you won’t be able to speed up much (firstly, a remote connection, and secondly, mailers can limit the speed of receiving letters). It is possible to try to save on a connection/authorization in this case. To do this, don't create a new PHPMailer instance for each email, just change the Body/Subject/To/etc. and do send() - it should use one connection.
You can send faster if you use local SMTP (like Postfix on Linux). It can be configured to send both through an external relay (yandex, etc.) and directly (this case requires configuration, otherwise the letters will not reach or fall into spam).
In reality, all this will not be sent much faster (because postfix will queue messages and send them in the background), but at least your script will work out much faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question