Mail_mime::setTo method request
| From: | Didier Galland | Date: | Fri, 23 Jan 2004 13:21:40 +0000 |
| Subject: | Mail_mime::setTo method request | ||
| Groups: | php.pear.dev php.pear.general | ||
| Request: | Send a blank email to pear-dev+get-25232@lists.php.net to get a copy of this message | ||
Hi,
I suggest to add add a setTo() method to the mail_mime class. Is it possible
??
function setTo($to)
{
$this->_headers['To'] = $to;
}
Without it, it is not possible to update the 'to' header after a first call
of $mail_mime->headers(). It would be useful to send several mails
todifferent recipients with the same instance (to avoid multiple call to a
heavy setHTMLBody() for ex.)
Code example (doesn't work because headers() will not override the internal
_headers property):
$mime = &new Mail_mime("\r\n");
$headers['From'] = $from;
$mime->setTXTBody($message);
$mime->setHTMLBody($very_heavy_html_so_i_dont_want_to_make_this_in_the_forea
ch);
$body = $mime->get();
foreach ($recipients as $recipient) {
$email = $recipient->email;
$name = $recipient->name;
$headers['Subject'] = 'Your report dear ' . $name;
$headers['To'] = '"' . $name . '" <' . $email .
'>';
$hdrs = $mime->headers($headers);//works only once
/**
second call (and following) in foreach fails and does not update
$mime->_headers['to']
because in Mail_mime class::headers() the internal property _headers
overrides the passed parameter in this line:
$this->_headers = array_merge($headers, $this->_headers);
//*/
/**
the new suggested method setTo($to) would make it working by calling in my
script
$mime->setTo($to);
other solution = inversion of arguments in the second array_merge() in
mail_mime::headers()
//*/
$mail =& Mail::factory('mail');
$mail->send($email, $hdrs, $body);//html message allways sent to the same
recipient
}