Good day everyone, I'm looking for the best way to automate my purchases through my web app. Hope you can give a good advice or suggestion
Let's say we have one product, one user, and order table,
Product name is MusicMixes, product price is 50$, product attachment is Music.mp3 (with a size of 50mb)
User name is Juan and user email is juan@mail.com
Here's the current scenario/application that I have. I am using phpmailer() to send an email with attachments to buyers after a successful purchase using this syntax.
$mail->addAttachment("uploads/".$file_name);
Assuming the buyer bought MusicMixes product, the behavior of the process will be:
- The web app will get the User's name and email using session.
- The web app will fetch the data of the Product (incl. the Attachment) from database based from the Product ID/Name
- The web app will then send an email to the buyer, the structure is like this.
if(isset[post]){
//get user data from session
$name = $session[name]
$email = $session[email]
//get data based on id/name
stmtSelect = select * from product where ID/Name=MusicMixes
//Insert data to db
stmtInsert = insert into order (name,email,productid,productname,productattachment,productprice)
if(stmt execute){
//send email with attachment
$mail->Addattachement....
}
//Process is done
}
I'm encountering a long loading process before the process is submitted/done because I assume that the web app will fetch the attachment (big size, 50mb) and upload into phpmailer() and send it to the user. Typically, if the user refreshes/cancelled/did something to the browser while it is still loading. There are times that the attachments/email are not sent but the data is being saved into the DB.
My question is...
Is it possible like to save it first to database so the loading will be done instantly.
purchase.php = saves data to DB
then after some time maybe after 3-5 minutes, theres something (I can't figure it out) within the web app that will trigger mailSend.php
mailSend.php = sends the email w/ attachments based on DB.
There is somewhat another PHP file/other instances that will handle the mailing process to get the necessary info from the DB then send the email with attachments to the user? so that it doesn't affect the loading time/UX for the user. Something like its loading an email function, the backend is doing its thing without interrupting the user. I can't really explain myself so Hopefully you guys get what I meant.
Thanks for the big help!