简体   繁体   中英

Save attachments with php mailer

I'm using PHP mailer and sometimes our SMTP service is unavailable (can't connect etc). In these cases I want to save the email for a later retry.

Is there a simple way of doing this? If not, I can save the parts myself, but is there a simple way of saving the attachments?

I'm using PHP 5.6.7

You're approaching this the wrong way. The right way to handle this does not involve PHPMailer. What you're asking for is an MTA, ie a mail server that will handle queuing and retrying for you. Just install postfix and use PHPMailer to submit to it on localhost and your queuing problems will magically be solved.

If you want to track the status of deliveries, you should make use of the pipe features of the mail server

OK - it seems there wasn't a simple solution, so I have done it the hard way and it works, so I'm happy. I used sqlite3 to keep the database queue local so that it didn't have to rely on external connections that may be down and stored the attachments in a similar folder tree to allow duplicate file names and I used a scheduled task to cycle through the queue and resend the email and delete the files and the entry from the sqlite3 database. If it fails again, then it gets re-queued.

In the main Phpmailer class.

PHPMailer::SmtpSend():

if(!$this->SmtpConnect()) {
      throw new phpmailerException($this->Lang('smtp_connect_failed'), self::STOP_CRITICAL);
    }

Perhaps you could catch that Exception and serialise the mailer object. Then try sending again later (unserialise/send).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM