PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Multiple recipients from MySQL query gives only one mail ?

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail
View previous topic :: View next topic  
Author Message
Peter_E



Joined: 16 Feb 2011
Posts: 1

PostPosted: Wed Feb 16, 2011 3:19 pm    Post subject: Multiple recipients from MySQL query gives only one mail ? Reply with quote

EDIT: I found one answer myself:
By moving the "}" to the bottom of the script (just before the "?>") both email addresses will get their emails. But then 2 different mails are sent, not just 1 mail with 2 recipients. But that's OK to me (I think).
:end of EDIT

Probably very simple: A query returns in this (test-)case 2 emailaddresses out of a MySQL database. PEAR should send a mail to both of them.
But it doesn't! It sends only 1 email, to the last one (let's say: [email protected]_site.nl). The first one (let's say: [email protected]_site.nl) is skipped, whatever I change or try.
Both email addresses look good on screen (when "echo" them).

What can I do in order to make both customers get their emails?

This is the code:

<?php

$query = "SELECT * FROM customers WHERE sales > 1000 ORDER BY name";
$sql = mysql_query($query) or die ( mysql_error( ) );

include('Mail.php');
include('Mail/mime.php');

while($record = mysql_fetch_object($sql)) {
$email = $record->customer_email;
$recipients = $email.=", ";
}
$sender = "My email <[email protected]_site.nl>";
$subject = "Test Email";
$text = 'This is a text message.';
$html = '<html><body><p>This is a html message.</p></body></html>';
$crlf = "\n";
$headers = array(
'To' => $recipients,
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get();
$headers = $mime->headers($headers);

$mail =& Mail::factory('mail');
$mail->send($recipients, $headers, $body);

?>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Mail All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement