selecting all emails from database

I’m trying to make a news letter feature that sends a message to all emails in a specific table.
I have the table ‘rss’ filled with email addresses. I want to store the emails in an array and then use the mail function to send the message to all the addresses that are in the array. (is it possible?)
I think mainly the query is wrong here… any help is appreciated.

[php]
if(empty($_POST[‘message’]) === true || empty($_POST[‘subject’])=== true) {
$errors[] = ‘Both fields are required.’;
} else {
$subject = $_POST[‘subject’];
$message = $_POST[‘message’];
$emails = array();
$emails = mysql_query("SELECT * FROM rss WHERE email");
mail($emails, $subject, $message, ‘From: me’);
}
[/php]

[php]

<?php if(empty($_POST['message']) === true || empty($_POST['subject'])=== true) { $errors[] = 'Both fields are required.'; } else { $subject = $_POST['subject']; $message = $_POST['message']; $query = mysql_query("SELECT email FROM rss"); $emails = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_assoc($emails)) { mail($rows['email'], $subject, $message, 'From: me'); } } ?>

[/php]

the loop should send an email for each message if it doesnt work i think foreach would work better good luck

I’m getting error message saying
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Resource id #10’ at line 1

any idea?

my mistake.
[php]

<?php if(empty($_POST['message']) === true || empty($_POST['subject'])=== true) { $errors[] = 'Both fields are required.'; } else { $subject = $_POST['subject']; $message = $_POST['message']; $query ="SELECT email FROM rss"; $emails = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_assoc($emails)) { mail($rows['email'], $subject, $message, 'From: me'); } } ?>

[/php]

hmm… where do you get the email value from?

mail($rows[‘email’], $subject, $message, ‘From: me’);

I copied your code and I get error ‘Resource id #10again

show me your code.

i will test it

[php]

if(empty($_POST) === false) {
	
	$subject = $_POST['subject'];
	$message = $_POST['message'];

	if(empty($_POST['message']) === true || empty($_POST['subject'])=== true) {
		$errors[] = 'Both fields are required.';
	} else {
		
		$query = mysql_query("SELECT email FROM rss");
		$emails = mysql_query($query) or die(mysql_error());

		while($rows = mysql_fetch_assoc($emails)) {
			mail($rows['email'], $subject, $message, 'From: me');
		}
	}
}[/php]

replace everything
[php]

<?php if(empty($_POST) === false) { $subject = $_POST['subject']; $message = $_POST['message']; if(empty($_POST['message']) === true || empty($_POST['subject'])=== true) { $errors[] = 'Both fields are required.'; } else { $query = "SELECT email FROM rss"; $emails = mysql_query($query) or die(mysql_error()); while($rows = mysql_fetch_assoc($emails)) { mail($rows['email'], $subject, $message, 'From: me'); } } } ?>

[/php]
on the post that i commented my mistake you did not copy my codes

thanks :slight_smile: works now

as soon as i posted back after your error should have work but you didnt copy my fixed codes.

you welcome glad that i helped

Sponsor our Newsletter | Privacy Policy | Terms of Service