Jump to content

[SOLVED] E-MAIL problems


topflight

Recommended Posts

I have this mass email script but it is not working please help:

<?php
include 'db.php'; 
$message = $_POST['message'];
$subject = $_POST['subject'];
if(isset($_POST['submit'])){
if((!$message | !$subject)){
echo'You are missing some required information please go back and fill out all the required information';
} else {

$sql = mysql_query("SELECT * FROM members ORDER BY 'id' ASC");
$result = mysql_fetch_assoc($sql);
$bcc = $result["email"];
for ($index=0; $index < count($bcc); $index++)
  { 


$from = 'email';
$to = 'email';
$header .= "Bcc: ".$bcc."\r\n"; 
$headers .= 'From: <[email protected]>' . "\r\n";

mail($to,$subject, $message, $headers);
}}}?>

Link to comment
https://forums.phpfreaks.com/topic/154646-solved-e-mail-problems/
Share on other sites

You are never looping the results returned:

 

<?php
include 'db.php'; 
$message = $_POST['message'];
$subject = $_POST['subject'];
if(isset($_POST['submit'])){
    if((!$message | !$subject)){
        echo'You are missing some required information please go back and fill out all the required information';
    } else {

        $sql = mysql_query("SELECT email FROM members ORDER BY `id` ASC");
        if (mysql_num_rows($sql)) {
            $bcc = array();
            while ($result = mysql_fetch_assoc($sql)) {
                $bcc[] = $result["email"];
            }
            $from = 'email';
            $to = 'email';
            $header = "Bcc: ".implode("\r\n", $bcc)."\r\n" 
            $header .= 'From: <[email protected]>' . "\r\n";

            mail($to, $subject, $message, $header);
        }
    }
}
?>

 

Sorry, my mistake, the bcc emails should be seperated by a comma not a newline:

 

<?php
include 'db.php'; 
$message = $_POST['message'];
$subject = $_POST['subject'];
if(isset($_POST['submit'])){
    if((!$message | !$subject)){
        echo'You are missing some required information please go back and fill out all the required information';
    } else {

        $sql = mysql_query("SELECT email FROM members ORDER BY `id` ASC");
        if (mysql_num_rows($sql)) {
            $bcc = array();
            while ($result = mysql_fetch_assoc($sql)) {
                $bcc[] = $result["email"];
            }
            $from = 'email';
            $to = 'email';
            $header = "Bcc: ".implode(", ", $bcc)."\r\n" 
            $header .= 'From: <[email protected]>' . "\r\n";

            mail($to, $subject, $message, $header);
        }
    }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.