Help... I am trying to build a dynamic associative array
Posted: Thu May 14, 2009 6:22 pm
I am trying to build an a dynamic associative array that is added to each time inside of the loop.
This is so I can send the email and the name to the swift mailer. But it only returns the first one
and I have not found a way to add in other people to the array that will not break the code.
It has to be done dynamically for it to work as it is passed in from a form. I have taken all of the
data that is real and put some fake data in for security purposes.
This is so I can send the email and the name to the swift mailer. But it only returns the first one
and I have not found a way to add in other people to the array that will not break the code.
It has to be done dynamically for it to work as it is passed in from a form. I have taken all of the
data that is real and put some fake data in for security purposes.
Code: Select all
//start loop
foreach ($projmembers as $key => $value) {
//echo "key:" . $key . "->" . $value;
$membr = mysql_real_escape_string($value);
$x=explode(",",$membr);
// Information passed in from the previous form seperated by commas.
// This information is then split into memberID, membername, and memberemail.
$memberID = $x[0];
$memberName = $x[1];
$memberEmail = $x[2];
// Here is my main problem. I am trying to add to a dynamic associative array
// which is going through a loop so I can use these emails as emails to CC out.
$ccemails = array($memberEmail => $memberName);
//$insert = mysql_query("INSERT INTO ec_project_members VALUES ('','$projectID','$memberID')") or die("There was an error while inserting database data : " . mysql_error());
}
//end loop
//Set msgbody
$msgbody = "<center><h3>bodyofemail " . $projname . "</h3><p><b>Project Objectives: </b>";
$subject = "SaberNet Employee Contribution - " . $projname;
//Send the trasport to send the email(s)
$transport = Swift_SmtpTransport::newInstance('smtp.server.com', 25)
->setUsername('blah@blah.com')
->setPassword('password');
//Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
//Prep the email(s)
$message = Swift_Message::newInstance($subject)
->setFrom(array('blah@censoredemail.com=> 'blimey'))
->setTo(array('blah@censoredemail.com' => 'blah'))
->setCc($ccemails)
->addpart($msgbody,'text/html');
//Send the email(s)
$mailresult = $mailer->send($message);
}