Zend_Mail send and Zend_Progressbar

231 Views Asked by At

Does anybody know a good example how to send mail with attachments and display a progressbar in JavaScript (jQuery)?

1

There are 1 best solutions below

0
On

You're probably going to have to guess the amount of time it takes and update the progress bar based on that.

Given that PHP doesn't have threading, I would suggest having a database queue for deliveries, and have an external PHP process triggered from the main site (or via cron) that processes the deliveries on the side, marking on the database the current status on each delivery: NOT_PROCESSED, IN_PROGRESS, CONNECTING, CONNECTED, SENDING_DATA, ACCEPTED, FAILURE_X . You can query the database for the status on each delivery via Ajax.

If PHPMailer internally uses the standard PHP mail() function, which uses a relay SMTP server in your machine, you cannot have that much information about status (which you would have if you created the sockets yourself), you can have just three main states NOT_PROCESSED, IN_PROGRESS, FAILURE_X.

Is it possible to send mail asycronously using PHP while giving user feedback on delivery?

Otherwise maybe you could update the progress bar after each little step. Something arbitrary like this:

  1. Set mail recipient
    • update progress bar 25%
  2. Set mail from address
    • update progress bar 50%
  3. Set mail headers
    • update progress bar 75%
  4. Send mail
    • update progress bar to 100%

This, however, is really inefficient.. And the end result would probably be the user seeing the progress bar jump really fast through the first three (25%, 50%, 75%) and then be stuck on the 75% for a extra second or two and then be done..