I wrote this script that sends a receipt to the client about his order, but he has a problem:
He will not wait for the PDF script.
Thus, it just requires a PDF script and starts to execute it and sends mail while the PDF script is still working on the PDF. I am sure there is a way to postpone the email script, but to complicate things:
All order.php is executed with a jquery ajax call, and the script will wait for php to complete, and then tells the browser that the request has been completed. Thus, he can wait more than five minutes for the client to wonder why he took so long.
Therefore, I need him to wait for the creation of the PDF file, and then send the mail, but he should not leave the client waiting.
Here is my code:
<?php $addid = "orderid.txt"; $current = file_get_contents($addid) + 1; echo $current; file_put_contents($addid, $current); ?> <?php // Lue tilauksen ID sähköpostia varten $orderid = "orderid.txt"; $ordernumber = file_get_contents($orderid); // Kirjoita kuitti require('receipt.php'); ?> <?php //Lähetä tilausvahvistus require_once('mail/class.phpmailer.php'); $path = "kuitit/kuitti".$orderid.".pdf"; $bodytext = ' Olemme vastaanottaneet tilauksenne '. $ordernumber .'. Tilaamanne tuotteet löytyvät liitteestä.' ; $email = new PHPMailer(); $email->From = ' no-reply@coverlinefilms.fi '; $email->FromName = ' no-reply@coverlinefilms.fi '; $email->Subject = 'Olemme vastaanottaneet tilauksenne ' . $ordernumber; $email->Body = $bodytext; $email->AddAddress(' christian.nikkanen@gmail.com '); $email->AddAttachment($path, 'kuitti777.pdf'); return $email->Send(); ?>
Pdf script
user1537415
source share