mass email

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

mass email

Post by Wldrumstcs »

im a newb, so be gentle. ok, what i need to do is created a page like 'admin.php' where i type something into a textarea and it sends to all the emails in a column in a mysql DB. I have a script, but it does not actually send the emails out, so i am baffled. Help me out and tell me what I have to do.

Code: Select all

<form method="post" action="<?php echo $PHP_SELF?>">
	<p><textarea rows="7" name="tidbit" cols="38"></textarea></p>
	<p>&nbsp;</p>
	<p><input type="submit" value="submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

<?
if ($submit) {

mysql_connect("localhost","----","----") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("-----rs") or die ("Unable to select requested database.");
 
$result = mysql_query("SELECT email FROM members")
    or die("Invalid query: " . mysql_error());


while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { 
$to .= $line['email'].","; 
} 
$to = substr($to, 0, -1); 
$subject = "Your weekly TidBit"; 
$message = $tidbit; 
$headers = "From: webmaster@tidbitfacts.com"; 
mail($to, $subject, $message, $headers); 

} ?>
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

PHP dosen't automatically read form variables anymore. You need to change

Code: Select all

$message = $tidbit;
to

Code: Select all

$message = $_POST['tidbit'];
I don't know if thats whats preventing your email being sent though.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

If that really is the case, then viewtopic.php?t=511 would be essential reading as the script would break on $submit also.
Post Reply