View Full Version : getting a $value into array

11-04-2012, 12:55 AM
I am attempting to email to multiple recipients. I am using swiftmailer and following their guidelines. When I try to get the admins to email to it is erroring

Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given

The outputted format from my db is
$admins = "'email_1@email.com', 'email_2@email.com'";

The code from swiftmailer required for multiple is

$message->setTo(array('some@address.tld', 'other@address.tld'));

I have attempted everything I can think of to output in the same format as this, ie.


This appears to echo them in the right format for the mailer however I still get the exception. If I manually right the addresses into the code as oppose to using a variable from the DB query it works. So it doesnt like echoing in the value string.. Any help please!?

11-04-2012, 01:59 AM
Let me get this straight you store multiple admin emails in one database field and you separate them by comma in your database?
I don't know why you would store them like that but if you lose the single quotes around the emails and do something like this:

$admins = "email_1@email.com, email_2@email.com";

$admin_ary = explode(',', $admins);

Then it should work.

But I would still recommend you two store the emails in separate rows.
That way you could do a while loop to make your email array.

11-04-2012, 11:47 AM
Thanks, that did the trick. The reason that I have data stored int his way is that it is a configuration table for the group. Most will have only 1 email but occasionally there may be a requirement for 2-5 people to receive the email. Cheers