Re: Mail, array of recipients
| From: | Justin Patrin | Date: | Fri, 06 Aug 2004 22:57:56 +0000 |
| Subject: | Re: Mail, array of recipients | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13991@lists.php.net to get a copy of this message | ||
On Fri, 6 Aug 2004 18:08:30 -0400, Sean Brown <sean@sean-brown.com> wrote:
> 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)) {
> $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 one
> recipient.";
> }
>
> Has anyone run into this? Is there a fix?
>
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);
}
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
>
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--