anynaseo Posted August 19, 2011 Share Posted August 19, 2011 I Have the following issue and I spend my whole day looking for it. I have a database with a simple admin where I add/delete values. The database structure is the following: id, zip, email The database is called zipdatabase Here is the mailing part: //headers $headers = "From: <$Email>"; $headers .= "\r\nBcc: <$Bcc>\r\n\r\n"; // send email $success = mail($EmailTo, $Subject, $Body, $headers); The variable $Bcc must come from the database. I am really ignorant so I only got to a point on how to echo the results I need (and this works): $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { echo "{$r['email']}, "; } ?> For a zip I get more than one result so when I tried using this $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); while($row = mysql_fetch_array($result)) { $Bcc = "{$r['email']}, "; } echo "Bcc" ?> It only gives me one result. What I noticed is I have 2 issues: - I can't extract the BCC from the database - I don't know how to add more email addresses to the bcc field, I only managed to add more addresses to the $Emailto like: $EmailTo = "[email protected], [email protected]"; $Bcc = "[email protected]"; All these variables are defined by a webform and it works flawlessly except the database problem: $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $ZIP = Trim(stripslashes($_POST['ZIP'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=contacterror.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "ZIP: "; $Body .= $ZIP; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; Sorry for my ignorance and hope someone here can help. The webform works perfectly except the bcc from the database part. Quote Link to comment https://forums.phpfreaks.com/topic/245241-sendmail-and-pick-all-the-addesses-from-a-database/ Share on other sites More sharing options...
joel24 Posted August 20, 2011 Share Posted August 20, 2011 you need to use the concatenate operator to combine the BCC addresses, or put them into an array and implode like so $query = "SELECT email FROM zipdatabase WHERE zip = '$ZIP'"; $result = mysql_query($query); $bccs = array(); while($row = mysql_fetch_array($result)) { $bccs[] = $r['email']; } $bccs = implode(",",$bccs); #should echo [email protected], [email protected] etc echo $bccs; Quote Link to comment https://forums.phpfreaks.com/topic/245241-sendmail-and-pick-all-the-addesses-from-a-database/#findComment-1259637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.