Re: Mail, array of recipients

From: Date: Fri, 01 Oct 2004 23:57:14 +0000
Subject: Re: Mail, array of recipients
References: 1 2 3 4 5 6  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-14728@lists.php.net to get a copy of this message
Justin Patrin wrote:
Is there any disadvantage in making a method setTo($to){$this->_headers['To'] = $to;} in mail_mime ?
No, I see no reason that would be bad. Put in a feature request for Mail_mime. To do it now, use this, then. $mime = &new Mail_mime("\r\n"); $mime->setTXTBody($message); $mime->setHTMLBody($html_message); $body = $mime->get(); $hdrs = $mime->headers($headers); $mailObj =& Mail::factory($driver,$options); foreach ($recipients as $recipient) { $hdrs['To'] = $recipient; $result = $mailObj->send($recipient, $hdrs, $body); } I was sure to have tried this... Anyway, it works fine ! Thanks... It proves mail_mime is not so necessary to set headers...
Here is the entire example (tested). Perhaps it could help somebody (it would have help me if I could get it in Mail package docs!). require_once('Mail/mime.php'); require_once('Mail.php'); $recipients = array('email1@domain.ltd', 'email1@domain.ltd', 'email1@domain.ltd'); $message = 'some text blah blah'; $html_message = ' <html> <head> <title>My html test.</title> </head> <body> My html test. </body> </html>'; $driver = 'smtp'; $driverOptions = array(); $driverOptions["host"] = 'smtp.host.ltd'; $driverOptions["auth"] = false; $crlf = "\r\n"; $headers = array(); $headers['From'] = "Postmaster <postmaster@domain.ltd>"; $headers['Subject'] = 'subject of mail'; $hdrs["Reply-To"] = 'replyto@domain.ltd'; $mime = &new Mail_mime($crlf); $mime->setTXTBody($message); $mime->setHTMLBody($html_message); $body = $mime->get(); $hdrs = $mime->headers($headers); $mailObj = &Mail::factory($driver, $driverOptions); foreach ($recipients as $recipient) { $hdrs['To'] = $recipient; $result = $mailObj->send($recipient, $hdrs, $body); if (PEAR::isError($result)) {
       return $result->getMessage() . ' '. $result->getUserInfo();
} else {
       return "Success.\n";
} }

« previous php.pear.general (#14728) next »