on 25/03/02 6:31 PM, anti-blank ([EMAIL PROTECTED]) wrote:

> I've got this script here to send out a mail whenever I enter an update to my
> site to my mailing list.
> The problem is it wants to dump everyone's email into the To field, and since
> I don't want to give my
> users email addresses away I need to convert this to the bcc field.  Below is
> the original code and then
> the modification that I made (which doesn't seem to work).  Also if anyone has
> any idea how to include
> in this block a line to tell php to send this as HTML email as well that would
> be even more helpful.

To answer your question, you'd need to set the $to to a dummy address, or
*perhaps* to null, and use headers to add a Bcc line with the address on it.

Instead of $from, you should build a $headers var, of which Bcc is one of.

UNTESTED:
<?

$bcc = "";
$query = mysql_query("SELECT * FROM members");
while ($member = mysql_fetch_array($query))
  {
  if ($bcc == "")
    {
    $bcc = $member['email'];
    }
  else
    {
    $bcc .= ", " . $member['email'];
    }
  }
$from = "From: " . $setting_mail_email . "\r\n";
$to = "[EMAIL PROTECTED]";
$headers = $from.$bcc;

mail ($to, $setting_site_name, $mailpost, $headers) or $emailsuccess =
"Failure sending email.";

?>



HOWEVER, Instead of sending the email in one hit ie:

   "Bcc: [EMAIL PROTECTED], [EMAIL PROTECTED], etc"

Use the while loop of your SQL query to send the mail individualy to each
recipient.

This has a few benefits:

1. They can see exactly which address they recieved the email through, which
is mighty helpfull for people like me with 10+ email address' all hitting my
one POP box

2. You can personalise the email with things like:
  a) Greeting them with their name
  b) "you are currently subscribed as [EMAIL PROTECTED],
     to remove your self, or modify your subscription, visit
     this URL: http://site.com/mail.php?subscriber_id=1&page=edit";

3. You can split the query into smaller chunks, for ISPs with limits on
script timeouts etc etc.

4. customise the content of the email to suit thier interests

Plus a heap more probably...


MY VERSION, UNTESTED:

<?
$mailpost = $mailpost;
$mailpost = str_replace("{setting_site_name}", $setting_site_name,
$mailpost);
$mailpost = str_replace("{setting_site_url}", $setting_site_url, $mailpost);
$mailpost = str_replace("{setting_mail_email}", $setting_mail_email,
$mailpost);
$mailpost = str_replace("{post_poster}", $cookie_username, $mailpost);
$mailpost = str_replace("{post_headline}", $headline, $mailpost);
$mailpost = str_replace("{post_date}", date("M d, Y", time()), $mailpost);
$mailpost = str_replace("{post_post}", $post, $mailpost);
$to = "";
$from = "from: " . $setting_mail_email;

$query = mysql_query("SELECT * FROM members");
while ($member = mysql_fetch_array($query))
  {
  if ($to == "")
    {
    $to = $member['email'];
    mail ($to, $setting_site_name, $mailpost, $from) or $emailsuccess =
"Failure sending email.";
    }
  }
?>




> ORIGINAL CODE:
> $mailpost = $mailpost;
> $mailpost = str_replace("{setting_site_name}", $setting_site_name, $mailpost);
> $mailpost = str_replace("{setting_site_url}", $setting_site_url, $mailpost);
> $mailpost = str_replace("{setting_mail_email}", $setting_mail_email,
> $mailpost);
> $mailpost = str_replace("{post_poster}", $cookie_username, $mailpost);
> $mailpost = str_replace("{post_headline}", $headline, $mailpost);
> $mailpost = str_replace("{post_date}", date("M d, Y", time()), $mailpost);
> $mailpost = str_replace("{post_post}", $post, $mailpost);
> $to = "";
> $query = mysql_query("SELECT * FROM members");
> while ($member = mysql_fetch_array($query)) {
> if ($to == "") {$to = $member['email'];}
> else {$to .= ", " . $member['email'];}
> }
> $from = "from: " . $setting_mail_email;
> mail ($to, $setting_site_name, $mailpost, $from) or $emailsuccess = "Failure
> sending email.";
> if ($emailsuccess == "") {$emailsuccess = "Email Sent Successfully.";}
> }
> 
> 
> 
> My MODIFIED CODE:
> $mailpost = $mailpost;
> $mailpost = str_replace("{setting_site_name}", $setting_site_name, $mailpost);
> $mailpost = str_replace("{setting_site_url}", $setting_site_url, $mailpost);
> $mailpost = str_replace("{setting_mail_email}", $setting_mail_email,
> $mailpost);
> $mailpost = str_replace("{post_poster}", $cookie_username, $mailpost);
> $mailpost = str_replace("{post_headline}", $headline, $mailpost);
> $mailpost = str_replace("{post_date}", date("M d, Y", time()), $mailpost);
> $mailpost = str_replace("{post_post}", $post, $mailpost);
> $bcc = "";
> $query = mysql_query("SELECT * FROM members");
> while ($member = mysql_fetch_array($query)) {
> if ($bcc == "") {$bcc = $member['email'];}
> else {$bcc .= ", " . $member['email'];}
> }
> $from = "from: " . $setting_mail_email;
> mail ($bcc, $setting_site_name, $mailpost, $from) or $emailsuccess = "Failure
> sending email.";
> if ($emailsuccess == "") {$emailsuccess = "Email Sent Successfully.";}
> }
> 
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to