Need a little array help...

Discussion in 'PHP' started by GeorgeB., Sep 7, 2006.

  1. #1
    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?
     
    GeorgeB., Sep 7, 2006 IP
  2. Chaos King

    Chaos King Peon

    Messages:
    88
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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:
     
    Chaos King, Sep 7, 2006 IP
    GeorgeB. likes this.
  3. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Is King's code working for you?
     
    wmburg, Sep 7, 2006 IP
  4. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #4
    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 :)
     
    GeorgeB., Sep 7, 2006 IP
  5. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #5
    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:
     
    wmburg, Sep 7, 2006 IP
  6. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #6
    And the verdict is..
     
    wmburg, Sep 7, 2006 IP
    GeorgeB. likes this.
  7. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #7
    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 :D

    Thanks a lot for the help.

    green given.

    - George
     
    GeorgeB., Sep 7, 2006 IP
  8. wmburg

    wmburg Active Member

    Messages:
    300
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #8
    Awesome.

    NP! I just wanted to make sure that it was working for you.

    Thanks :)
     
    wmburg, Sep 7, 2006 IP
    GeorgeB. likes this.