Title

Sunday, 18 January 2015

Php mailer compile and store message for later sending


My question is can we compile and store messages as a draft in php mailer and then later on send each message?

Answer

I don't think so PHPMailer supports this feature. But you can do this by using DB Table. Create a table in database to store messages, recipients, from, headers, etc and send them by PHPMailer later from a CRON job.

Answer2

PHPMailer can't support this, because it conserves the Email message in Object which will die after the end of the script(the HTTP protocol works that way).

If you want to send them latter (say after 15 minutes) you need to use CRON job indeed and make a script looking in the database and sending emails.

If you want to send them in the Lifetime of the script (send them after the tag) you can simply do an array of emails and foreach them at the end

Answer3

You need create

  1. special method that will do save all mail that should be sent (in db)
  2. special method that will get all unsent mails and send them
  3. add to crontab method that send unset mails

That's all.

No comments:

Post a Comment