how to setup dynamic email string for setTo

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
eggnogg
Forum Newbie
Posts: 11
Joined: Wed Feb 15, 2006 7:31 pm

how to setup dynamic email string for setTo

Post by eggnogg »

basically that what i wanna do but i can't seem to do it nor have i found anyone that tried it before.
basically im receiving a string with emails as so

john@gmail.com, maria@gmail, etc@gmail.com

and i want to use those emails and place them in the setTo field but i can't

ive tried creating a string with each email delimited with ', like

'john@gmail.com', 'maria@gmail', 'etc@gmail.com'

placing it in a variable and setting that variable in the setTo field but that fails.

so, how would i go about and doing it?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how to setup dynamic email string for setTo

Post by Christopher »

I assume you are using the mail() function? It should work with just a comma between email addresses.

Have you read this page carefully:

http://www.php.net/manual/en/function.mail.php

It gives many good examples.
(#10850)
eggnogg
Forum Newbie
Posts: 11
Joined: Wed Feb 15, 2006 7:31 pm

Re: how to setup dynamic email string for setTo

Post by eggnogg »

a little newb here, for that matter
...
no, i am using smpt...

and the following config:

Code: Select all

$transport = Swift_SmtpTransport::newInstance($setting_smtp_email['smtp_host'], $setting_smtp_email['smtp_port'],'ssl')
		  ->setUsername($setting_smtp_email['smtp_user'])
		  ->setPassword($setting_smtp_email['smtp_pass'])
		;
$mailMessage = Swift_Message::newInstance()
		  ->setSubject($subject)
		  ->setFrom(array($setting['setting_email_fromemail'] => $setting['setting_email_fromname']))
		  ->setSender(array($setting['setting_email_fromemail']))
		  ->setTo(array($recipient_email)) /* it's this guy that i haven't figured out how to use when setting more than one emails */
		  ->setBody($message, 'text/html')
		  ->addPart($textPlain_message, 'text/plain')
		;
                $result = $mailer->batchSend($mailMessage);
eggnogg
Forum Newbie
Posts: 11
Joined: Wed Feb 15, 2006 7:31 pm

Re: how to setup dynamic email string for setTo

Post by eggnogg »

resolved:
set up an array variable instead of a string.

Code: Select all

$var = array('a','b')
->setTo($var)
regards
Post Reply