I'm trying to write a generic function for my mailing system.
What I'm planning to do is.
- Get all the to-address values in an array and the required information
- Store all the values in the database.
I started with two dimensional associate array, but I'm not able to retrieve the values in the foreach.
Finally the foreach echo statement should be like
insert into my_table('name','to_address','subject','message','add_cc') values ('Author1','[email protected]','Subject','Message','[email protected]');
insert into my_table('name','to_address','subject','message','add_cc') values ('Author2','[email protected]','Subject','Message','[email protected]');
insert into my_table('name','to_address','subject','message','add_cc') values ('Author3','[email protected]','Subject','Message','[email protected]');
Here below is my code, I know the problem is with the foreach loop. I would be happy even if the associate array is minimized without the numeric sequence lik [0],[1],[2].
<?php
$to_address = array(
array( 'Name' => "Author1", 'Email' => '[email protected]' ),
array( 'Name' => "Author2", 'Email' => '[email protected]' ),
array( 'Name' => "Author3", 'Email' => '[email protected]')
);
$subject = "Subject";
$message = "Message";
$add_cc = "[email protected]";
sendMail($to_address,$subject,$message,$add_cc);
function sendMail($to_address,$subject,$message,$add_cc) {
foreach ($to_address as $key => $val) {
foreach ($val as $key1 => $val1) {
print_r($val1);
}
}
}
?>
Thanks, Kimz
EDIT:
In other words, I'm not able to loop the $to_address value and I need a help.