OK I have an array of emails. $recipients = array('sadas@haah.com','safd@sdfsdf.com','kjhkljjk@jjjj.com','kjkjlhk@killemall.mil'); I need to pass it to this piece of code WITHOUT using a for loop. if (!$swift->hasFailed()) { $swift->send( '"Guys Name" <$recipients>', '"MySite.com" <my@return_email.com>', 'THE Subject Here ); $swift->close(); echo "sent to $recipients<br />"; $swift->loadPlugin(new Swift_Plugin_Errors); } PHP: Now of course right now when I run this code it doesn't send the mails and echoes sent to Array. swiftmailer simply will not allow you to put the emailing code in a for loop so I need another way. Any suggestions?
Here you go. if ( !$swift->hasFailed() ) { foreach ( $recipients as $email ) { $swift->send ( '"Guys Name" <'.$email.'>', '"MySite.com" <my@return_email.com>', 'THE Subject Here', ) $swift->close(); echo "sent to $email<br />"; } $swift->loadPlugin(new Swift_Plugin_Errors); } PHP:
No it's not. As I said. You can't use for loops. Don't know how he missed that. But at least he tried to help
Swift accepts arrays for a to address $recipients = array('sadas@haah.com','safd@sdfsdf.com','kjhkljjk@jjjj.com','kjkjlhk@killemall.mil'); if (!$swift->hasFailed()) { $swift->send( $recipients, '"MySite.com" <my@return_email.com>', 'THE Subject Here ); $swift->close(); echo "sent to $recipients<br />"; $swift->loadPlugin(new Swift_Plugin_Errors); } PHP: or 2-dimensional arrays $recipients = array ( array("Their Name","their@email.com"), array("John Smith","asdf@asdfas.com"), array("Jane Doe","jane@aoeom.com") ); if (!$swift->hasFailed()) { $swift->send( $recipients, '"MySite.com" <my@return_email.com>', 'THE Subject Here ); $swift->close(); echo "sent to $recipients<br />"; $swift->loadPlugin(new Swift_Plugin_Errors); } PHP:
That it works perfectly. I've been busy coding the rest of the script around it thats why I didn't reply. Now I'm sending multipart mime HTML and plain text emails like a champ Thanks a lot for the help. green given. - George