Hello!

Currently I have a form where the user can submit emails in a comma separated format to the $row in database $contacts. How can I set this up correctly so the user can email their contacts? As of right now the script emails everybody but just not in the correct email format. Thank You!

<?php

$formMessage = "";
$senderName = "";
$senderEmail = "";
$senderMessage = "";
if (isset($_POST['cusername']))
{

 
    // Gather the posted form variables into local PHP variables
    $senderName = $_POST['cusername'];
    $senderEmail = $_POST['cemail'];
    $senderMessage = $_POST['msg'];
    // Make sure certain vars are present or else we do not send email yet
    if (!$senderName || !$senderEmail ) {
 
         $formMessage = "The form is incomplete, please fill in all fields.";
 
    } else { // Here is the section in which the email actually gets sent

        // Run any filtering here
        $senderName = strip_tags($senderName);
        $senderName = stripslashes($senderName);
        $senderEmail = strip_tags($senderEmail);
        $senderEmail = stripslashes($senderEmail);
        $senderMessage = strip_tags($senderMessage);
        $senderMessage = stripslashes($senderMessage);
        // End Filtering
 $to = "$contacts";         

   $from = "";
        $subject = "Prospect For Property";
        // Begin Email Message Body
  $message = '<html><body>';
';

$message .= "</body></html>";
        // Set headers configurations
		 $headers = "MIME-Version: 1.0\r\n";

      
       

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        // Mail it now using PHP's mail function
        mail($to, $subject, $message, $headers);
        $formMessage = "Thanks, your message has been sent.";
        $senderName = "";
        $senderEmail = "";
        $senderMessage = "";
    } // close the else condition

} // close if (POST condition
?>

As of right now the script emails everybody but just not in the correct email format.

Please explain, what format is not correct ?

Please explain, what format is not correct ?

I would like to hide the recipients addresses. As the script lies now, all the recipients addresses show when emailed.

Use Bcc and put it in the additional header. See an example in the documentation.

Use Bcc and put it in the additional header. See an example in the documentation.

That is a good example but I can't get it to fire off the emails in the bcc field. The emails come from a comma separated row in the database. Works fine when I use only the $to field. Let me know if you see anything in the script.

<?php

$formMessage = "";
$senderName = "";
$senderEmail = "";
$senderMessage = "";
if (isset($_POST['cusername']))
{

 
    // Gather the posted form variables into local PHP variables
    $senderName = $_POST['cusername'];
    $senderEmail = $_POST['cemail'];
    $senderMessage = $_POST['msg'];
    // Make sure certain vars are present or else we do not send email yet
    if (!$senderName || !$senderEmail ) {
 
         $formMessage = "The form is incomplete, please fill in all fields.";
 
    } else { // Here is the section in which the email actually gets sent

        // Run any filtering here
        $senderName = strip_tags($senderName);
        $senderName = stripslashes($senderName);
        $senderEmail = strip_tags($senderEmail);
        $senderEmail = stripslashes($senderEmail);
        $senderMessage = strip_tags($senderMessage);
        $senderMessage = stripslashes($senderMessage);
        // End Filtering
 $to  = '' . ', ';

   $from = "";
        $subject = "Prospect For Property";
      $message = '<html><body>';
$message .= '
';

$message .= "</body></html>";
        // Set headers configurations
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'To:  Bbizzl<bbizzl@bbizzl.com>' . "\r\n";
$headers .= 'From:no-reply <no-reply@no-reply.com>' . "\r\n";
$headers .= 'Cc:' . "\r\n";
$headers .= 'Bcc: $contacts' . "\r\n";
        // Mail it now using PHP's mail function
        mail($to, $subject, $message, $headers);
        $formMessage = "Thanks, your message has been sent.";
        $senderName = "";
        $senderEmail = "";
        $senderMessage = "";
    } // close the else condition

} // close if (POST condition
?>

Use Bcc and put it in the additional header. See an example in the documentation.

In the context of correspondence, blind carbon copy (abbreviated Bcc) refers to the practice of sending a message to multiple recipients in such a way that conceals the fact that there may be additional addressees from the complete list of recipients. This concept originally applied to paper correspondence and now also applies to email.
Source

There still has to be one recipient in the To: (which you removed, you can put yourself there).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.