To send mail from script, I've always used the htmlMimeMail class; I prefer smtp over mail and that class does all the dirty work. I guess it's showing its gray hair but it's served me well, it does everything I need, and as 3rd party code goes I get along with it well.
This evening I've been toying with imap. I was about to look at the composition & sending stuff but it made me wonder, is there any advantage?