Adding recipients by means of an array

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
User avatar
joho
Forum Newbie
Posts: 16
Joined: Tue Oct 17, 2006 4:34 am
Location: Stockholm, Sweden

Adding recipients by means of an array

Post by joho »

JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I added a few recipients like this:

Code: Select all

$rcps = new array ();
for ($i=0; $i<count($myrecips); $i++)
  $rcps[] = array ('', $myrecips[$i]);
This resulted in a message being created with a header like this:

To: "" <admin@mydomain.com>

I assume I did something wrong? :idea:


JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You didnt add the recipient name in the array like so..

Code: Select all

$rcps = new array ();
for ($i=0; $i<count($myrecips); $i++)
  $rcps[] = array ('Recipient name here', $myrecips[$i]);
User avatar
joho
Forum Newbie
Posts: 16
Joined: Tue Oct 17, 2006 4:34 am
Location: Stockholm, Sweden

Post by joho »

Indeed; and that is intentional -- I may (or may not) have a name.

(sorry about the bad format in the original post)
User avatar
joho
Forum Newbie
Posts: 16
Joined: Tue Oct 17, 2006 4:34 am
Location: Stockholm, Sweden

Proposed changes

Post by joho »

My proposed change to the way the recipient array is handled is as follows:

If an array-item in the passed list contains only one element, use it as the recipient's e-mail address and set the recipient's name to nothing, otherwise carry on as the current code does. Perhaps this should be an option, but possible nonetheless.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Proposed changes

Post by Chris Corbyn »

joho wrote:My proposed change to the way the recipient array is handled is as follows:

If an array-item in the passed list contains only one element, use it as the recipient's e-mail address and set the recipient's name to nothing, otherwise carry on as the current code does. Perhaps this should be an option, but possible nonetheless.
Hmmm that's already how it works. One-dimensional reads each element as an address. 2-dimensional reads names and addresses.

Code: Select all

$recipients = array('address@one.tld', 'address@two.tld', 'address@three.tld'); //1-dimensional

$swift->send($recipients, .... ); //Send to each of the recipients
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: Proposed changes

Post by JayBird »

d11wtq wrote:
Hmmm that's already how it works. One-dimensional reads each element as an address. 2-dimensional reads names and addresses.
i think he means if you had a 2-dimensional array, but some of the names may not be entered, so have a default value when the name is empty.
User avatar
joho
Forum Newbie
Posts: 16
Joined: Tue Oct 17, 2006 4:34 am
Location: Stockholm, Sweden

Post by joho »

Indeed; I may not know the status of each "data pair" before I create the recipients array. And when it's available, it's of course always nicer to present a name along with the address. But I don't think a construct of
To: '' jon@doe.com
is a good idea ;)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

joho wrote:Indeed; I may not know the status of each "data pair" before I create the recipients array. And when it's available, it's of course always nicer to present a name along with the address. But I don't think a construct of
To: '' jon@doe.com
is a good idea ;)
Point taken :) I'll make some changes when I get in from work.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Gahh I forgot to make this change when I just put the new release out :(
User avatar
joho
Forum Newbie
Posts: 16
Joined: Tue Oct 17, 2006 4:34 am
Location: Stockholm, Sweden

Post by joho »

Don't sweat it; it's not a show stopper. I've removed the usage of recipient names for now, and just supply the function with an array of e-mail addresses. It works, and I can live with it for now.
Post Reply