Hi,
I finally managed to create a simple newsletter script that pulls the emails from a database and sends a html-message to the recipents by using a form. The script works fine, but when I send out the emails all the recipents can see all the other recipents in the "To" field when viewing the mail in Outlook or otherwise.
<?php require_once("db.php"); ?>
<?php
if ($_POST['submit'] == TRUE) {
$subject = $_POST['Subject'];
$message = $_POST['Message'];
$headline = $_POST['Headline'];
$message2 = '
<html>
<head>
<title>Newsletter</title>
</head>
<body bgcolor="#b5b6b1">
<p><b>'.$headline.'</b><br>
<br>'.nl2br($message).'</p>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: bla@bla.com' . "\r\n";
$query = mysql_query('SELECT * FROM newsletter');
$mails = '';
while ($r = mysql_fetch_array($query))
{
$mails .= $r['Email'] . ',';
}
mail($mails, $subject, $message2, $headers);
echo "Mail was sent to:<br>";
echo "$mails";
}
else
{
?>
<h3>Send Newsletter</h3>
<form method="post" action="<?php echo $PHP_SELF ?>">
Subject: <input name="Subject" size="44" maxlength="255">
<br>
Headline: <input name="Headline" size="44" maxlength="255">
<br>
Message: <textarea name="Message" rows="20" cols="40"></textarea>
<br>
<input type="submit" name="submit" value="Send Newsletter">
</form>
<?
}
?>
I tried using the BCC function, but for some reason it only sends it to my primary email (currently testing it with two of my own emails).
$headers .= 'Bcc: ' . $mails . "\r\n";
mail("bla@bla.com", $subject, $message2, $headers);
Is there anything wrong with the way I tried to use the BCC-function? And is it possible to somehow send one and one mail out to each recipent so they only see their own email in the "To" field? My php knowledge is limited, especially when it comes to arrays, anyone know how to do this?