Reputation: 4671
I'm using PhpMailer to send e-mails. It's working fine.
But in some cases I don't want to wait for the send function to return, specially because it can take a while sometimes. I just want to send and finish the funcition right away.
Is it possible to achieve this?
This is a sample code I'm using (nothing different from the basics).
try {
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
// ...other options...
$mail->send();
return true;
} catch (Exception $e) {
return $e;
}
Upvotes: 2
Views: 1895
Reputation: 640
Like jeroen mentioned, you should use queues to achieve this. If you ever configured the cron to work with PHP, this have the similar principle except that it doesn't repeat the same task by schedule but executes any task you provide one-by-one in a queue. You can even give priorities to these tasks. I suggest you to start with beanstalkd.
Upvotes: 0
Reputation: 37818
You don't need to use ajax or configure your own queueing system to do this. Just use a local mail server - which implicitly has a built-in queueing system that you don't need to configure - and you can submit messages to it in a fraction of a second. There is some performance advice on the PHPMailer wiki.
Upvotes: 1