/    Sign up×
Community /Pin to ProfileBookmark

A Simple Mailing List – easy to do ?

Hello,

Can someone please help me out with a very basic mailing list concept I have.

In a profiles table which stores the user_id, I have an ENUM which states ‘Y’ or ‘N’ if a user is on the mailing list. I also have the users table, which stores the users email address.

How easy is it to combine all of the email addresses into one go and send a message out to users who have ‘Y’ in the maillist field. I’d heard about a ‘rowdata’ type.

Can someone please help me out

[code=php]
<?php # – mail_out.php
// This is the mail_out page for Pictures of Scotland admin to email members if they are ‘subscribed’ to the mailing list.

// Inclyde the configuration file for error management again
require_once (‘../includes/config.inc.php’);

// Set the page title and include the HTML header.
$page_title = ‘Mailing List Admin’;
include (‘../includes/aheader.html’);

if (isset($_POST[‘submitted’])) { // Handle the form.

require_once (‘../../mysql_connect.php’); // Connect to the database

$query = “SELECT u.username, u.email, p.user_id FROM users u, profiles p WHERE p.maillist=’Y'”;
$result = mysql_query ($query) or trigger_error(“Query: $queryn<br />MySQL Error: ” . mysql_error());
if (mysql_affected_rows() == 1) {
// if it ran OK

// Send the email.
$body = $_POST[‘mail_out’];
while ($row = mysql_fetch_array($result)) {
mail($row[’email’], ‘Pictures of Scotland Newsletter’, $body, ‘From:Pictures of Scotland<[email protected]>’);
}

// Finish the page
echo ‘<H3>Your mail-out has been sent successfully to those on the Mailing List.</h3>’;
include (‘../includes/afooter.html’); // Include the HTML footer.
exit();

}

mysql_close(); // Close the connection with the Database

} // End of the main Submit conditional.

?> <h2>Mailing List</h2><p>Type in a message below to be sent to everyone on the
mailing list.</p><form action=”mail_out.php” method=”post”> <fieldset> <p><b>Enter Mail Out here :</b><br><textarea name=”mail_out” COLS=”60″ ROWS=”8″></textarea></p></fieldset>
<div align=”center”><input type=”submit” name=”submit” value=”Submit Mail Out” /></div><input type=”hidden” name=”submitted” value=”TRUE” />
</form>
<?php
include (‘../includes/afooter.html’);
?>
[/code]

profiles table

[code]
CREATE TABLE `profiles` (
`pid` tinyint(4) NOT NULL auto_increment,
`nickname` varchar(15) NOT NULL default ”,
`sex` enum(‘M’,’F’) NOT NULL default ‘M’,
`age` tinyint(3) NOT NULL default ‘0’,
`interests` text NOT NULL,
`country` varchar(50) NOT NULL default ”,
`maillist` enum(‘Y’,’N’) NOT NULL default ‘Y’,
`user_id` tinyint(4) NOT NULL default ‘0’,
PRIMARY KEY (`pid`)
)
[/code]

users table

[code]
CREATE TABLE `users` (
`user_id` int(10) unsigned NOT NULL auto_increment,
`username` varchar(16) NOT NULL default ”,
`email` varchar(40) NOT NULL default ”,
`pass` varchar(40) NOT NULL default ”,
`first_name` varchar(15) NOT NULL default ”,
`last_name` varchar(30) NOT NULL default ”,
`active` varchar(32) default NULL,
`registration_date` datetime NOT NULL default ‘0000-00-00 00:00:00’,
PRIMARY KEY (`user_id`),
UNIQUE KEY `username` (`username`),
)
[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@invisionauthorJan 30.2006 — *bump*

Any help with the above would be very much appreciated.

Thanks for taking a look.
Copy linkTweet thisAlerts:
@invisionauthorJan 31.2006 — *bump*

Any help would be greatly appreciated,

Thanks.
×

Success!

Help @invision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...