Web Hosting Talk







View Full Version : PHP Mailing list manager


jgriff64
05-30-2002, 05:40 PM
Hi all, I am looking for a good php mailing list manager. Does any one have any suggestions.
Thanks in advance

mwatkins
05-30-2002, 05:42 PM
To run a single list? To run multiple lists? To offer to vhost clients?

jgriff64
05-30-2002, 05:45 PM
Thanks for the quick response. Sorry for the lack of info.

Originally to run a single list, to send announcements to our customers.

Will need to be able to import addresses or intagrate into current database.

Thanks again.

mwatkins
05-30-2002, 06:13 PM
If you already have your list of customers in a database, I'd just write a small mailing function. A form, a mail function, and away you go.

Unless you have thousands of names to mail to, you don't need to do much more than that.

For example:

You have a database with

firstname
lastname
email
send_mail (True or False)


function sendmail($from,$to,$subject,$message) {
$pipe=popen("/usr/sbin/sendmail -t -i -r \"$from\" -f \"$from\" ","w");
if (!$pipe)
return false;
fputs($pipe,"Return-path: <$from>\n");
fputs($pipe,"From: $to\n");
fputs($pipe,"To: $to\n");
fputs($pipe,"Reply-To: $from\n");
fputs($pipe,"Subject: $subject\n");
fwrite($pipe,$message);
return !pclose($pipe);
}

// main
// take the results of a form and post it to everyone with send_mail = "Y"
// this is more or less working code however you'll need to sub your own 'query' function or deal direct with MySQL PHP calls
// your form will have text field "subject" and text area field "message" within it
// this is a quick from memory effort, your mileage may vary


$db = mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($db) or die();

$sql = "select firstname, lastname, email from users
where send_mail = 'Y' ";
$result = @mysql_query($sql,$db);
$nrows = mysql_num_rows($result);
for ($i=0;$i<$nrows;$i++) {
$r = mysql_fetch_array($result);
$to = "{$r["firstname"]} {$r["lastname"]} <{$r["email"]}>";
sendmail($from, $to, $subject, $message);
}



And there you go. A few minutes work. The above code may have the odd little problem, but that's all the time I have for this. If useful, terrific, and if not, perhaps someone else will take it and run.

mwatkins
05-30-2002, 06:23 PM
And for my Python evangelism brownie points of the day, just having to recall a few PHP code snippets reminds me why I am happy that all my web work is now in Python. One is busy and full of nasty extra delimiters, superfluous characters ({} $ ; etc), while the other is clean and easy to read.


# this is python, not php:

def mail_users(sender, subject, message, sql):
db.query(sql)
result = db.fetchall()
for row in result:
recipient = "%s %s <%s>" % (row.firstname, row.lastname, row.email)
sendmail(sender, recipient, subject, message)


In either PHP or Python cases, some sanity and error checking is required.

Sadly I still have to maintain lots of legacy PHP code.

jgriff64
05-31-2002, 05:15 AM
Thanks mwatkins, for your time. It is very kind of you. Best Regards.

mwatkins
05-31-2002, 10:10 AM
You are very welcome. I don't know if you have any PHP programming experience but even (especially?) if not, I encourage you to try.

Excellent on-line or Windows help file documentation, complete with user experiences and tips, is available here:
http://www.php.net/docs.php

Good luck,
Mike