Build message?

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
Kaitlyn2004
Forum Newbie
Posts: 15
Joined: Wed May 30, 2007 7:46 am

Build message?

Post by Kaitlyn2004 »

How can I "build" the message so that I could, for example, write it to a file rather than actually SEND it?

Including headers and everything, of course...
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Build message?

Post by Chris Corbyn »

Kaitlyn2004 wrote:How can I "build" the message so that I could, for example, write it to a file rather than actually SEND it?

Including headers and everything, of course...
Easy way:

Code: Select all

$stream =& $message->build();
file_put_contents($file, $stream->readFull());
I the message is huge and would take PHP over its memory limit you can stream it into a file instead:

Code: Select all

$fp = fopen($file, "wb");
$stream =& $message->build();
while (false !== $bytes = $stream->read(8192)) {
  fwrite($fp, $bytes);
}
fclose($fp);
Post Reply