Multiple Recipients: Explode a string!
Posted: Sun Jan 06, 2008 10:55 pm
Hi again,
I have sorted my SWIFT scripts out, and I am able to send multipart emails, with attachments. I gotta give it to you Chris, it is the most efficient I have found!
I know that exploding strings into arrays is General PHP forum stuff, but it relates to Swift, so if needs be you can move it, or whatever.
My form enables the user to select from a select list of potential recipients, and clicking one populates this into a text area below. The reason is so they have a pre-set list of recipients with correct names and addresses from the database, and also the ability to edit these addresses once selected, or add an address to the end of the string.
However, since I have changed to use Swift, I cannot use a single string for multiple recipients, eg:
Mick <mick@nodomain.com>, Sally <sally@nodomain.com>, etc <etc@..>, ...
Instead, I require a single line for each recipient, as mentioned at http://www.swiftmailer.org/wikidocs/v3/ ... recipients:
Normally, splitting a string into an array is fine, and i'm using the code below (assuming string is presented very simply delimited by a comma (,)):
This code splits it into:
But how would I gather each name with each email and present it in the appropriate format DYNAMICALLY (could be 1 recipient, or 100):
Sorry it was so long winded, but i'm all about detail!
Cheers,
Mick
I have sorted my SWIFT scripts out, and I am able to send multipart emails, with attachments. I gotta give it to you Chris, it is the most efficient I have found!
I know that exploding strings into arrays is General PHP forum stuff, but it relates to Swift, so if needs be you can move it, or whatever.
My form enables the user to select from a select list of potential recipients, and clicking one populates this into a text area below. The reason is so they have a pre-set list of recipients with correct names and addresses from the database, and also the ability to edit these addresses once selected, or add an address to the end of the string.
However, since I have changed to use Swift, I cannot use a single string for multiple recipients, eg:
Mick <mick@nodomain.com>, Sally <sally@nodomain.com>, etc <etc@..>, ...
Instead, I require a single line for each recipient, as mentioned at http://www.swiftmailer.org/wikidocs/v3/ ... recipients:
Code: Select all
//Recipients
$recipients =& new Swift_RecipientList();
$recipients->addTo("mick@nodomain.com", "Mick");
$recipients->addTo("sally@nodomain.com", "Sally");
$number_sent = $swift->send($message, $recipients, "my-address@domain.tld");Code: Select all
<?php
$recipients= "Mick,mick@nodomain.com,Sally,sally@nodomain.com,hellokitty,hellokitty@nodomain.com";
$exploded = explode(",", $recipients);
for($i = 0; $i < count($exploded); $i++){
echo "$exploded[$i] <br />";
}
?>Code: Select all
Mick
mick@nodomain.com
Sally
sally@nodomain.com
hellokitty
hellokitty@nodomain.comCode: Select all
//Recipients
$recipients =& new Swift_RecipientList();
$recipients->addTo("mick@nodomain.com", "Mick");
$recipients->addTo("sally@nodomain.com", "Sally");
$recipients->addTo("hellokitty@nodomain.com", "hellokitty");
...Cheers,
Mick