Dynamic $recipients->addTo

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
poida_gtir
Forum Newbie
Posts: 2
Joined: Tue Oct 21, 2008 12:28 am

Dynamic $recipients->addTo

Post by poida_gtir »

Just wondering if any one has any advice on adding recipients dynamically. Below is what i have tried might give you a better idea of what im trying to do. Name and email stored in a database want to build the list dynamically and send. My database query works and the swiftmail works with manually entered addresses. Any help would be great.

Code: Select all

$recipients =& new Swift_RecipientList();
 
//Gets recipient information
    $db = new EmailAddress();
        if ($db->IsError())
            {
            $msg = "<div class=\"error\"><strong>ERROR:</strong> Cannot connect to database</div>";
            }
                        
        else
            {
            $result = $db->getAllActive($mailingListID);
            while($row = $db->FetchArray($result))
                {
                $sendToName = $row['name'];
                $sendToEmail = $row['email'];
                
                $recipients->addTo($sendToName, $sendToEmail);
                }
                
            }
        $db->FreeResult($result);
poida_gtir
Forum Newbie
Posts: 2
Joined: Tue Oct 21, 2008 12:28 am

Re: Dynamic $recipients->addTo

Post by poida_gtir »

never mind im stupid had

Code: Select all

$recipients->addTo($sendToName, $sendToEmail);
instead of

Code: Select all

$recipients->addTo($sendToEmail, $sendToName);
Post Reply