Current location: Hot Scripts Forums » Programming Languages » PHP » Help email user question


Help email user question

Reply
  #1 (permalink)  
Old 04-18-06, 05:43 PM
ahowardmiller ahowardmiller is offline
New Member
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Help email user question

I'm trying to write a script to email all the users of my database and for the life of me I can't get it to work. I've tried everything I could find on this and other fourms and nothing is working.
I have a table in my database called users with a row called email to store their addresses. I have a form that posts the subject, message, and sender, but I can't figure out how to send it to multiple recipients. It works just fine with one recipient but if I query the database for all the email address it only sends it to the first email address.
Any help would be appreciated.

Here's the code I'm using:
PHP Code:

The Form page:

<
html>
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Send Users Email Area</title>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Edit User Area</title>
<
body>
<
form method="post" action="sendmail.php">
Email: <input name="sender" type="text"><br>
Subject: <input name="subject" type="text"><br>
Message:
<
textarea name="message" rows="10" cols="30">
</
textarea>
<
input type="submit">
</
form>

</
body>
</
html
PHP Code:

The sendmail.php

<?php
include ('config.php');
/*Here we are going to declare the variables*/
$message $_POST['message'];
$subject $_POST['subject'];
$sender $_POST['sender'];
 unset(
$email); 
$counter=0
$res=mysql_query("SELECT email FROM users"); 
$numb_user2=mysql_num_rows($res); 
$numb_user=$numb_user2 1
while(
$all mysql_fetch_object($res) ): 
$email .= $all->email
if(
$counter $numb_user$email .= ", "
$counter++; 
endwhile; 
//Save visitor name and entered message into one variable:
$mailheader "From: $sender\r\n";
$mailheader .= "Reply-To: $sender\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";
mail($email$subject$message$mailheader) or die("Failure!");
echo 
"Thank You!";
?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-18-06, 06:22 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Try this

PHP Code:

<?php

include ('config.php');

/*Here we are going to declare the variables*/
$message $_POST['message'];
$subject $_POST['subject'];
$sender $_POST['sender'];

//Save visitor name and entered message into one variable:
$mailheader "From: $sender\r\n";
$mailheader .= "Reply-To: $sender\r\n";
$mailheader .= "MIME-Version: 1.0\r\n";

$query mysql_query("SELECT email FROM users");

while (
$row mysql_fetch_array($query))
{
    
mail($row["email"], $subject$message$mailheader) or die("Failure!");
}

echo 
"Thank You!";

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-18-06, 08:59 PM
ahowardmiller ahowardmiller is offline
New Member
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Talking Thanks

It worked. Is there anything I need to worry about when the users get into the hundreds? Thanks again. I tried row before but couldn't get it to work. Have a great day.

Take care,
Aaron

One additional question. What if I wanted to make the email bcc instead of To?

Last edited by ahowardmiller; 04-18-06 at 09:26 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Preventing multiple user from loging in using the same username and password digioz PHP 2 09-14-05 02:53 PM
2 flash websites for sale metamorph General Advertisements 5 01-09-05 11:03 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 07:02 AM


All times are GMT -5. The time now is 01:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.