asynchronous operation phpmailer #3085
Replies: 1 comment
-
If you have sufficient control over your server (i.e. you have root access), an easier and more reliable way to do this is to run a local mail server such as postfix. Sending to the local mail server from PHPMailer will be very fast (easily hundreds of messages per second), and it will queue and relay on to the destination, including handling bounces, greetdelay, deferrals, etc. While it's tempting to rewrite everything in PHP, mail servers are built to do this, and they are much better at it. As a fallback, I would not go this naive route as it relies on too many external things. A better approach is to use a queue (redis or beanstalkd work well, but you can use your existing database too) that's driven from a script triggered by cron, systemd, or whatever. This is how queued jobs work in, for example, Laravel. However, again bear in mind that you're building and maintaining a custom system to replicate what mail servers already do much better. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
I just finished a natuw project with phpmailer and I wanted to share it with you.
my problem was the response time to the customer after sending an email, because of sending large images
which could give me a timeout delay.
forward operation (synchronous operation)
Client PC (mail image)->send server->mail creation ->send mail->client response if mail sent correctly or not
the problem is sending emails and responding can take a long time if there are large images.
now (asynchronous operation).
Client PC (mail image)->send server->bdd storage->if the storage is ok customer response and at the same time I send with a shell the email(s) to the requested people.
for important images the response time is divided by 2.
if necessary, I have traceability and I can send the email(s) to the people concerned
Here is the code I made, if it can help anyone it is with pleasure.
Sincerely
David LECUYER
Beta Was this translation helpful? Give feedback.
All reactions