Re: Mail Queue problem - when sending to multiple email addresses, headers only use first address
| From: | Richard Lund | Date: | Tue, 25 Jan 2011 15:42:52 +0000 |
| Subject: | Re: Mail Queue problem - when sending to multiple email addresses, headers only use first address | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-30938@lists.php.net to get a copy of this message | ||
Never mind, I tried the IRC channel again and found the answer:
$hdrs = $mime->headers($hdrs);
should be
$hdrs = $mime->headers($hdrs, true);
The second parameter is overwrite - it would not overwrite the header when
submitting a new one.
Problem solved - hopefully this will help someone else along the way.
May I suggest putting this into the mail queue tutorial?
I spent 4 days on this issue...
Thanks!
On Tue, Jan 25, 2011 at 8:43 AM, Richard Lund <rlund1@lunds.us> wrote:
> Can anyone point me to a place (forum, IRC, etc.) where someone might know
> the answer to this question?
> It's been a few days, and I haven't received any answer, and I need to
> figure this out for this project...
> Already spent 2 hours in the official pear IRC channel and also saw no
> response to my question there.
> Same with the Codewalkers forum.
>
> Any other places I could try?
>
> Thanks!
>
>
> On Fri, Jan 21, 2011 at 9:19 AM, Richard Lund <rlund1@lunds.us> wrote:
>
>> Hi.
>>
>> I am working on a broadcast email system for site users. The list of
>> names/email addresses is loaded into PHP, then I go through every entry in
>> the email list and use $mail_queue->put to add it to the database.
>> The recipient field works correctly, but the headers field always stays
>> the same using the data from the first user.
>> So I end up with multiple rows of data in the mail_queue table, the
>> recipient is always different as it should be, but headers is the exact same
>> data for every recipient including the TO field, so every recipient receives
>> the email but on analyzing the header only sees it addressed to the first
>> person on the list, thus making their email address public.
>>
>> Here is the code I use:
>>
>> // initialize MIME
>> $mime = new Mail_Mime();
>> $mime->setHTMLBody($msg_body_html);
>> $mime->setTXTBody($msg_body_text);
>> $body = $mime->get();
>> // end initialize MIME
>>
>> $mail_queue = new Mail_Queue($db_options, $mail_options);
>>
>> $sql = "call pListRecipients(" . $msg_list . ")";
>>
>> $rs = ExecSql($sql);
>> while ($result = $rs->fetch_assoc())
>> {
>> if($result['fldFullName'] != '')
>> $msg_to = $result['fldFullName'] . "<" .
>> $result['fldEmail'] . ">";
>> else
>> $msg_to = $result['fldEmail'];
>>
>> $hdrs = array(
>> 'From' => $msg_from,
>> 'To' => $msg_to,
>> 'Subject' => $msg_subject
>> );
>> $hdrs = $mime->headers($hdrs);
>> $mail_queue->put($msg_from, $msg_to, $hdrs, $body);
>> }
>>
>>
>> This always happens for the first email in this loop - when I start a new
>> loop, it keeps the header for that loop the same.
>>
>> I experimented with this. I added $x and $x++ into the while loop and
>> added $x to $msg_subject on each loop, so each email should have a different
>> subject. Still the entire header in each database entry used the same
>> subject.
>> I used var_dump just before put, so I know that the data on my end is
>> created correctly.
>>
>> The only way I found so far to create a workaround for this was to take
>> the initialize MIME block and place it inside the while loop - then
>> everything works.
>> I also tried unset($hdrs) before assigning the array without success.
>>
>> Is this normal behavior?
>> Do I really have to initialize the MIME object on every while run, or is
>> there something else I'm missing?
>>
>> I looked at the pear PHP code and couldn't find anything there that would
>> explain this, but then I've only worked with PHP for about 6 months, so I
>> might be missing something simple here...
>>
>> Thanks in advance for any help you can give me!
>>
>> cu,
>> Richard
>>
>>
>