Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Mailer compile and store message for later sending

Tags:

php

phpmailer

Can we compile and store messages as a draft in PHP mailer and then later on send each message?

like image 286
Tariq Avatar asked Nov 24 '25 15:11

Tariq


2 Answers

It is possible to do this with PHPMailer. After configuring the PHPMailer instance with everything you'd normally need to send the message, do not call send() - instead call preSend() (which constructs the message) and then get the message content using getSentMIMEMessage(), e.g.

$mail->preSend();
$message = $mail->getSentMIMEMessage();

$message will then contain a complete RFC822 message which you can stick in a database, queue or whatever to send later. To do the actual sending later, you could make use of PHPMailer's SMTP class directly. To see how to drive that class, look at PHPMailer's smtpSend() function.

like image 114
Synchro Avatar answered Nov 27 '25 04:11

Synchro


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.

like image 30
Vin.AI Avatar answered Nov 27 '25 03:11

Vin.AI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!