I have an email form that has possible email addresses to send to designated by checkboxes. I already have them in an array and it grabs all of them fine, I can echo them to the screen but I can’t seem to get them to explode and loop through them propery to format them to send.
@violent_jApr 27.2004 — #hmm .. i can't quite understand what you mean, you say that you have all the addressess in an array and that you can echo them to the screen, but you can't use them to send email ?
@NevermoreApr 27.2004 — #If you have them as an array you don't need to use explode; that's only if they're a single string. If they are an array. just substitute your array name into the implode. [code=php] $subject="hi"; $body="body text"; $headers="From: [email][email protected][/email]"; $to=implode(",",$email_array); mail($to,$subject,$body,$headers);
[/code]
If you aren't actually using an array, you need to turn it into an array, or replace characters to make a valid 'to' list. For example, if the email addresses are separated by spaces, just use $email_array=explode(" ",$your_string); to create the array for the preceding example.
@NevermoreApr 27.2004 — #Looks like you did post, and beat me to it. Try this: (assumes that everything else works) [code=php] <% /* ------------------------------------------------------------------------- */
if($_POST['submit']) { if(isset($_POST['checkbox'])) { $emails = $_POST['checkbox']; echo "The following email addresses have been selected:<br />"; foreach($emails as $key => $value)
{ echo "$value <br />";
}
} else { echo "no email address selected"; } {
}
} function send_mail ( $Data ) {
$To = implode(",",$_POST['emails']); $Subject = "Request for Programming change"; $Msg = stripcslashes ( $Data["client"] . "n" . $Data["issue"] . "n" . $Data["change"] . "n" . $Data["timeframe"] . "n" . $Data["price"] . "n"); $From = "From: " . stripcslashes ( $Data["mail"] ); $Headers = trim ( $From . "n" );
/* Send the email using the SMTP mail() */ mail ( $To, $Subject, $Msg, $Headers ); } %> <html> <head> <title>Request for Programming Change</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>
<body bgcolor="#FFFFFF"> <? send_mail ( $HTTP_POST_VARS ); ?> </body> </html> [/code] In PHP variables aren't available to functions unless they're global, and after using the foreach you will only be left with one email address to send to rather than all of them. Also note that tags like those could cause problems on other systems, you should probably change to <?php and ?>, unless you have a legitimate reason not to.