I have a newsletter that sends out a notification to members with in 30 days of expiring. The way it works is the script populates an <option> from the members table who fall with in the thirty days. All I want to do is be able mask the $to recipients and use bcc.
code below: any hep would be much appreciated.

<?php 
include "../includes/db.php";
include "../includes/function.php";
checkAdminLogin();
include "header.php";
include "../fckeditor/fckeditor.php";

$db = new Database();
$db->connect();
$error = "";
$emails = "";
$arr = array();

if( count($_POST) )
{

    if( !empty($_POST['txtSUB']) && !empty($_POST['msgDESC']) && !empty($_POST['cmbEmail']))
    {

        $emails = "1";

        if( $emails == "1" )
        {
            $to = "";
            foreach( $_POST['cmbEmail'] as $v )
            {
                $to .= $v . ", ";
            }
            $sub = sql_replace($_POST['txtSUB']);
            $msg = sql_replace($_POST['msgDESC']);

            $headers = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";


            $headers .= 'From: [email]administrator@beneteaufirst367.org[/email]' . "\r\n"; 
            if( @mail($to, $sub, $msg, $headers ) )
            {
                echo "<script type='text/javascript'> 
                            alert('Newsletter has been sent to your selected members'); 
                            window.location.href = 'member_exp.php';
                      </script>";
            }
            else
            {
                echo "<script type='text/javascript'> 
                            alert('Error while sending newsletter, please try again latter');
                      </script>";
            }
        }
    }
    else
    {
        $error = "&nbsp;&bull;&nbsp;All fields are required<br>";
    }
}
?>

Recommended Answers

All 5 Replies

try this -

<?
include "../includes/db.php";
include "../includes/function.php";
checkAdminLogin();
include "header.php";
include "../fckeditor/fckeditor.php";

$db = new Database();
$db->connect();
$error = "";
$emails = "";
$arr = array();

if( count($_POST) )
{
	if( !empty($_POST['txtSUB']) && !empty($_POST['msgDESC']) && !empty($_POST['cmbEmail']))
	{
	
		$emails = "1";
	
		if( $emails == "1" )
		{
			$to = "test@test.com";	//some dummy email id or your own id
			foreach( $_POST['cmbEmail'] as $v )
			{
				$bcc .= $v . ", ";
			}
			$sub = sql_replace($_POST['txtSUB']);
			$msg = sql_replace($_POST['msgDESC']);
			
			$headers = "MIME-Version: 1.0" . "\r\n";
			$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
			
			
			$headers .= 'From: administrator@beneteaufirst367.org' . "\r\n";
			//---------------
			$headers .= "Bcc: ".$bcc."\r\n";
			
			if( @mail($to, $sub, $msg, $headers ) )
			{
				echo "<script type='text/javascript'>
				alert('Newsletter has been sent to your selected members');
				window.location.href = 'member_exp.php';
				</script>";
			}
			else
			{
				echo "<script type='text/javascript'>
				alert('Error while sending newsletter, please try again latter');
				</script>";
			}
		}
	}
	else
	{
		$error = "&nbsp;&bull;&nbsp;All fields are required<br>";
	}
}
?>

Network18
Thanks for answering my post.

I tried your code and at first it was erring out. I modified it a touch as shown below.

The problem I'm having now is that it only sends the Cc: to the first email on the list.

However if you look at the ---Original Message---- It shows the multiple Cc: addresses, the only one I received was jxx.sxxxxxx@att.net. Note: These are all real email accounts that I have access to, I just added the Xs to prevent spammers from reading this post and acquiring my email addresses.

It seems to me that the loop is not working properly. Any help you can offer would be me much appreciated.

----- Original Message -----
From: administrator@beneteaufirst367.org
To: jxxxxxxxx@pxxxxxxxxx.com
Cc: jxx.xxxxxxxxx@att.net ; jxxxxxxxxx@live.com ; jxxxxxxx@xxxxxxxxxxx.com ; jxxxxxxxx@xxxxxxs.com
Sent: Monday, October 12, 2009 12:52 PM
Subject: Try 9

This is test 9
---------------------------------------------- //end email


//New Code:
<?php
include "../includes/db.php";
include "../includes/function.php";

checkAdminLogin();

include "header.php";
include "../fckeditor/fckeditor.php";

$db = new Database();
$db->connect();

$error = "";
$emails = "";
$arr = array();

if( count($_POST) )
{
if( !empty($_POST) && !empty($_POST) && !empty($_POST))
{
$emails = "1";

if( $emails == "1" )
{
$to = "jspringer@peacefrogstudios.com";
$sub = sql_replace($_POST);
$msg = sql_replace($_POST);
$myBCC=",";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: administrator@beneteaufirst367.org' . "\r\n";

foreach( $_POST as $v)
{
$headers.='Cc:'. $v .  $myBCC . "\r\n";
}

if( @mail($to, $sub, $msg, $headers) )
{
echo "<script type='text/javascript'>
alert('Newsletter has been sent');
window.location.href = 'newsletterNew2.php';
</script>";
}
else
{
echo "<script type='text/javascript'>
alert('Error while sending newsletter, please try again latter');
</script>";
}
}
}        
else        
{        
$error = "&nbsp;&bull;&nbsp;All fields are required<br>";        
}        
}        
?>

Use below one:

$bcc="put email address"
$headers =$headers. 'Bcc:'.$bcc.'' . "\r\n";

that will solve your problem

Use below one:

$bcc="put email address"
$headers =$headers. 'Bcc:'.$bcc.'' . "\r\n";

that will solve your problem

Thanks for the response.

The $bcc is data driven. I have the app going to a generic $to recipient and want to be able to hide the real email recipients the user selected from a <select> in the form that is populated by the database. In the code I'm using $headers =$headers. 'Cc: for testing purposes. The problem I'm having is that when the email is sent, the $to recipient receives the test email and the first email address in the Cc: receives the test email. In the email it self it appears as the Cc: went to all emails on the list, but those email accounts never receive a physical email.

Thank you Networker 18 and poojamakhija for your suggestions. They were very helpful in getting the email Bcc to work.

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.