will just re-calling setBody each time reset the body of the e-mail? What about the multipart, where you attach? I don't want to keep attaching sections...
setBody() has been deliberately designed to act a little unexpectedly when you've got parts attached. It won't remove your parts, all it will do is set some text that appears before the MIME data (where you'd usually have a message saying "Sorry your mail client doesn't support MIME 1.0, please upgrade your mail client.". Effectively it becomes the fallback for really ancient mail clients.
If you need to remove the parts you've attached you'll have to use the detach() method:
attach() returns a string, but $text is a reference to an object before that happens.
Yay! Worked!
butt... it should use the $text in attach() before assigning it to the new $text...?
If I have JUST text to send, then it sends it as a MIME message, as makes sense. So in this case would I use the setBody() method on a plain text message, or what?
and then I guess above that, I would need to check if I am attaching anything... if not, use setBody() or whatever u say, but if attach, then I need to use the _Mesage_Part() method, right?
Kaitlyn2004 wrote:butt... it should use the $text in attach() before assigning it to the new $text...?
That's what does happen, but the error comes later because Swift then does some other things to the object when it comes to building the entire message structure. In PHP5 I think your code would have worked (sans the explicit reference operator). In PHP4, because you explictly create a reference it's treated a little differently
Oh, forgot to mention, you can keep the parts in variables and re-use the same parts repeatedly with different bodies if you want. You can still attach/detach them but it's probably good to keep them handy from an optimization point of view.
$part =& new Swift_Message_Part("XYZ");
$id = $message->attach($part); //Message is multipart
$message->detach($id);
$message->setBody("XYZ"); //Message is just plain
$message->setBody("");
$part->setBody("ABC");
$message->attach($part); //Message is multipart again