Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:40:03+00:00 2026-05-31T10:40:03+00:00

I am trying SwiftMailer to fetch the email addresses to an array() I have

  • 0

I am trying SwiftMailer to fetch the email addresses to an array() I have the original example and I know what I want to put in it but I can’t see the forest from the trees… any one out there with proper eyes please:

// Send the message
$result = $mailer->send($message);

// Send the message
$failedRecipients = array();
$numSent = 0;

Here is where I am struggling:

 foreach($groups as $value)
    { 
             echo "<h3>".$value."</h3>"; //this is working

    // get the email groups
    $sql="SELECT * FROM emails WHERE sendesstat=1 AND deleted=0 AND classhoz=\"".$value."\"";
    $query=mysql_query($sql);

    // fetch the emails from the group
    while($data=mysql_fetch_array($query))
                {
                  $emil="'".$data["email"]."' => '".$data["firstname"]." ".$data["surname"]."'";
                  echo $emil;

this echo is working but I can’t put in the $to[] array… (sorry) and this is how it should appear:

$to = array('receiver@domain.org', 'other@domain.org' => 'A name');

the issue is the given name => 'A name' I am being sick and I can’t find the syntax !!!

                  $to[ ]= $emil;            
                }
    }

foreach ($to as $address => $name)
{
  if (is_int($address)) {
   $message->setTo($name);
  } else {
   $message->setTo(array($address => $name));
}

 $numSent += $mailer->send($message, $failedRecipients);
}

printf("Sent %d messages\n", $numSent);

please please everything else is working now only this bit is missing. Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:40:05+00:00Added an answer on May 31, 2026 at 10:40 am

    You are defining the $to array the wrong way.

    Use this to add an item on the array

    $to[$data["email"]] = $data["firstname"]." ".$data["surname"];
    //  ^ Index           ^ Value
    

    Later On, when you use foreach loop it will well differentiated into $address and $name, just the way you are doing.

    foreach ($to as $address => $name) {
        echo $address;
        echo $name; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send email with Swiftmailer but it doesn't seem to be setting
Hello I am trying to send email messages with swiftmailer version 4.0.3. I get
trying to get my first HTML/CSS uni assignment sorted but have become a bit
Trying to create an array of structs (new to C), but I am getting
Trying to send a PHP email the easy way but I cannot work out
I am trying to fetch an email body and send a reply to the
Trying to post a simple form to my database but can't get it to
Trying to implement a sphere example code I found here on stackoverflow I have
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.