I have an app where I create/generate PDF on data retrieved from client side. When PDF is generated, I send those PDFs to desired emails and create download button, so customer can download that file too. The problem is that sending mails take some 10-15 seconds, maybe even more, before I can create download button. Is there a way I can put that email sending process in background, so I can skip directly to the download part of the code, instead of waiting for mailer to do all the tricks.
$name = md5(time());
$pdfoutput = $in->_config["path"] . '/PDFs/' . $name . '.pdf';
$mpdf->Output( $pdfoutput,'F' );
$subject = "Offer";
$body["html"] = "<b>Offer in html</b>";
$body["text"] = "Offer as text";
$files = array($pdfoutput);
$addresses = array("*******@hotmail.com");
// PROBLEMATIC PART
$mail->createEmails($addresses, $subject, $body, $files); // i want this proces to go in background
$pdfurl = $in->_config["url"] . "PDFs/" . $name . ".pdf";
return json_encode(array("status" => "ok", "reason" => "PDF CREATED!", "pdffile" => $pdfurl));