Re: Mail, array of recipients
| From: | DG | Date: | Fri, 01 Oct 2004 13:34:14 +0000 |
| Subject: | Re: Mail, array of recipients | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14710@lists.php.net to get a copy of this message | ||
Justin Patrin wrote:
On Fri, 6 Aug 2004 18:08:30 -0400, Sean Brown <sean@sean-brown.com> wrote:Once $myHdrs have been set with $myHdrs = $mime->headers($hdrs); You can no more change it. Once you have set the "To" header, it cannot be changed using the same instance of mail_mime object. On line 553 the method headers() of Mail_Mime override the $headers you want to set: $this->_headers = array_merge($headers, $this->_headers); So you have to make a new instance of mail_mime for each mail ! And to call again and again $body = $mail_mime_object->get(); This can easily kill your server. I think there is a lack of a setTo() public method (setting _headers private property) as suggested in pear_dev mailing list (http://marc.theaimsgroup.com/?l=pear-dev&m=107486411117568&w=2). Maybe I didn't understood the correct usage? I use this workaround: $mime->_headers['To'] = $headers['To']; my code = $mime = &new Mail_mime("\r\n"); $mime->setTXTBody($message); $mime->setHTMLBody($html_message); $body = $mime->get(); //85% of script time execution. impossible to put in the foreach foreach ($recipients as $recipient) {In the pear manual examples for the send method, it shows: send (mixed $recipients, string $headers, string $body); When I send out an e-mail from an app, it works, however, it does not seem to properly populate the "To" header based on the recipient array. What I mean by that is if I examine the headers after having received the email, the "To" header is completely missing. If I manually set the "To" header, it works. However, as you can imagine, unless my recipient array has only one person, this method wouldn't work. I'd have to loop through each individual in the recipient array, create a new object, then call the method again and again. Here's a snip from my code: $recipients = array('someone@example.com','someoneelse@example.com'); $smtparray = array(); $smtparray["host"] = 'smtp.example.com'; $smtparray["auth"] = FALSE; $crlf = "\r\n"; $from = "me@example.com (Web Master)"; $hdrs = array(); $hdrs["From"] = $from; $hdrs["Subject"] = $subject; $hdrs["Reply-To"] = $from_address; $mime = new Mail_mime($crlf); $mime->setTXTBody($plaintextmessage); $mime->setHTMLBody($htmlmessage); $body = $mime->get(); $hdrs = $mime->headers($hdrs); $mailObj =& Mail::factory('smtp',$smtparray); if (isset($recipients) && ($recipients)) {I would say this is expected bahavior. If you want all of them in the To use this: $hdrs['To'] = implode(', ', $recipients); $mail->send($recipients, $hdrs, $body); If you want each to have their own To: foreach($recipients as $recipient) { $myHdrs = $hdrs; $myHdrs['To'] = $recipient; $mail->send($recipient, $myHdrs, $body); } This won't make the job !! This foreach will send count($recipients) but always with the same "To" !$result = $mailObj->send($recipients, $hdrs, $body); if (PEAR::isError($result)) { return $result -> getMessage(); } else { return "Success."; }} else {return "Your e-mail has NOT been sent.<br>Please select at least onerecipient."; } Has anyone run into this? Is there a fix?
$mime->_headers['To'] = $recipient;//a setTo() method would be better
$hdrs = $mime->headers($headers); //without above workaround, cannot override internal _headers after first call
$mailObj =& Mail::factory($driver,$options);
$result = $mailObj->send($recipient, $hdrs, $body);
}
I believe it's set up this way so that you can: 1) Not have a To: 2) Set everyone in the To: 3) Set only one person in the To:Thanks, -- PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php