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

Can I send mail using PHP giving real-time user feedback?

I recently wrote a small application for our company intranet to send formatted emails to customers. The interface is pretty clean and only requires entering the job number, then it builds and sends mail. The mail, once built, receives several attachments from another server, and everything is automated. The PHPMailer library used .

Is there a way, using other technologies, perhaps, but still using PHP as the primary language, to show the progress of emails sent? I ran a robust error check to check if an email was actually sent, etc., but I'm missing a way to provide users with a visual clue about the actual mail delivery to the server using a progress bar, etc.

Is this possible using PHP and something like Ajax? How do you determine the progress of mail in transit?

+2


source to share


4 answers


I think the best option here is to estimate the time. You can check how long it takes 10MB mails to send to see the receive speed of your SMTP server. With this information, you can estimate the transmission time of any email based on its size and give your client some visual distraction based on that.



0


source


I'm not familiar with PHPMailer, but you definitely need the library's support to be able to query it about the status of the emails being sent.

Given that PHP does not have streaming, I would suggest having a database queue for delivery, and having an external PHP process run from the main site (or via cron) that handles shipments sideways, marking the current status in the database on every delivery: NOT_PROCESSED, IN_PROGRESS, CONNECTION, CONNECTION, SENDING_DATA, ACCEPTED, FAILURE_X. You can query the status database for each delivery via Ajax.

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

(FAILURE_X does represent many states as it explains the reason for the failure.)



One final consideration for using mail () is that the status you will be able to know is just the status from the local SMTP relay, which will always receive very quickly and you will not be able to determine if the mail was actually delivered to outbound the server (at least without having to interact with it or read mailq, which is frustrating to do).

RENOUNCEMENT

Given that even in a good case where you do know the status, you cannot know if the email was received on the other end and how long it will take, I'm not sure how useful such a construct was to be. Sure it would be fun to program, but I doubt it would be very helpful, maybe just some email standard deviation eye candy (emails can be lost in transit, if it doesn't try again, leave before trying again ) will be sufficient.

+5


source


If the email process can send back information, then it can update the progress bar or progress text with messages.

This is similar to how Wordpress updates / installs work. When the process is complete, a text is displayed that says each step: "Loading xxxx.xxx.xxx", "Plugin deactivation", "Plugin installation", "Reactivation attempt", "Reactivation successful": something similar. client side and server message sender: As the script runs, it sends back messages to the client.

As mentioned, this can actually actually get through to your server. You can indicate if the mail left your server successfully, but without any email confederation step, I think this is as much as possible.

0


source


I assume we have a chance to complete it, but cannot be sure if this decision has already been made by someone: (.

My thoughts:

since I know that you can work with the socket in the non-blocking mode stream_set_blocking () then you can try to use this approach to send emails through this non-blocking socket.

-1


source







All Articles