Jump to content

Recommended Posts

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.

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;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.