Page 1 of 3
Extremely Simple Mailing List
Posted: Sun Jul 11, 2004 7:52 am
by furiousweebee
I've looked all over the net for a few weeks now for a good mailing list manager, and haven't found one. I've installed and used around 20 different scripts so far but none of them are quite right.
As I've listed in another thread (
here), I'm making a user database. I want to be able to email everyone in this list via a simple form, and use a couple of the variables such as their first name in the email body. Unfortunately, two things are true right now:
1) I don't know where to begin; and
2) I suck ass.
If anyone could help me out I would be ever so grateful... I might even dance a little jig for your viewing pleasure. This is what I just saw in another thread but if I wanted to have a page with just two visible fields - subject and message - and have it automatically insert the information from the message field into the middle of a HTML template, would I just have to appropriately name an input field on a form preceding the following code? :
Code: Select all
<?php
$sendto = "SELECT * FROM street_team";
$sendto = mysql_query($sendto);
$subject = $_POST['subject'];
$message = '<html>
<body>';
$message .= 'some code above my message';
$message .= $_POST['message'];
$message .= 'some code below my message
</body>
</html>';
while ($sending = MySQL_fetch_array($sendto)){
$recipient = $sending['user_name'];
$remail = $sending['user_email'];
$to = $remail;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: {$recipient} <{$remail}>\r\n";
$headers .= "From: Official Mailing List <my@email.com>\r\n";
mail($to, $subject, $message, $headers);
}
?>
Posted: Sun Jul 11, 2004 11:29 am
by feyd
you could use your own design of tags for the fields like first_name and last_name from your database, like so (untested):
Code: Select all
<?php
$_POST['message'] = 'Dear {S_USALUTATION} {S_ULNAME}, {S_PMSG} and you are happily screwing around in php!';
function repData($match,$data)
{
return ( isset($data[$match]) ? $data[$match] : '{'.$match.'}' );
}
$sql = "SELECT * FROM street_team";
$query = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($query))
{
mail($row['user_email'],$_POST['subject'],preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$_POST['message']),$headers);
}
?>
this is taken from templating techniques..
Posted: Sun Jul 11, 2004 8:03 pm
by furiousweebee
Thanks for the reply... I'm really a novice with programming (most of the code I've posted on these forums is just grabbed from elsewhere and modified), so I'm not sure on a couple of things in your template example.
- How do I define what {S_USALUTATION} is (and others like that)? Or am I to replace that with {first_name} (as that is the field I use in my DB)?
- Where would I then define the $headers variables?
- How would I go about creating a template that the main message fits into?
- What would the performance of this script be like if there were a few thousand users being emailed?
Sorry for all the questions, I'm just a bit clueless at this point. Thanks again for the help.

Posted: Sun Jul 11, 2004 8:32 pm
by feyd
furiousweebee wrote:- How do I define what {S_USALUTATION} is (and others like that)? Or am I to replace that with {first_name} (as that is the field I use in my DB)?
the way it's set up there takes everything from $row as an associative array. So you can add to $row to add more, or you can make your own array of the values you'd like to use.
- Where would I then define the $headers variables?
you can defined it anytime before the preg_replace function is called, even in the same line.
- How would I go about creating a template that the main message fits into?
there's a multitude of ways to set it up. You can create a html page which has buttons that insert the variable text when clicked, much like the bbCode buttons found on replying to posts in this forum.
- What would the performance of this script be like if there were a few thousand users being emailed?
preg_* functions are generally very fast, so a script running several thousand times shouldn't take long at all.. the bottleneck will be the mail function, and the mail server. Your host may also have limits as to how many emails you can send at a time, or in a given period of time.
Posted: Sun Jul 11, 2004 9:04 pm
by furiousweebee
feyd wrote:furiousweebee wrote:How do I define what {S_USALUTATION} is (and others like that)? Or am I to replace that with {first_name} (as that is the field I use in my DB)?
the way it's set up there takes everything from $row as an associative array. So you can add to $row to add more, or you can make your own array of the values you'd like to use.
Sorry but I don't understand... if I had this information stored in a database (say for example, the "first_name" of a user), how would I get the form you showed me to insert the text in the email?
feyd wrote:Where would I then define the $headers variables?
you can defined it anytime before the preg_replace function is called, even in the same line.
So I can just put the following code in the line immediately before the mail function?
Code: Select all
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: {$recipient} <{$remail}>\r\n";
$headers .= "From: Official Mailing List <my@email.com>\r\n";
feyd wrote:How would I go about creating a template that the main message fits into?
there's a multitude of ways to set it up. You can create a html page which has buttons that insert the variable text when clicked, much like the bbCode buttons found on replying to posts in this forum.
Thanks but maybe I wasn't clear... I meant that if I wanted this form to email the users but automatically format the email with some HTML around my message when it sends it, how would I go about doing that? So basically the email, when sent, would be something like:
Code: Select all
<html>
<body>
<img src="header_image_defined_in_template.jpg">
Hello John,
Here is the message I entered in the email form.
<img src="footer_image.jpg>
</body>
</html>
You'll have to speak down to me. lol Thankyou for your ongoing help.

Posted: Sun Jul 11, 2004 9:41 pm
by feyd
furiousweebee wrote:feyd wrote:furiousweebee wrote:How do I define what {S_USALUTATION} is (and others like that)? Or am I to replace that with {first_name} (as that is the field I use in my DB)?
the way it's set up there takes everything from $row as an associative array. So you can add to $row to add more, or you can make your own array of the values you'd like to use.
Sorry but I don't understand... if I had this information stored in a database (say for example, the "first_name" of a user), how would I get the form you showed me to insert the text in the email?

will look for $row['first_name'] and $row['num'] respectively. If $row['num'] doesn't exist for instance, it remains unchanged in the message.
feyd wrote:Where would I then define the $headers variables?
you can defined it anytime before the preg_replace function is called, even in the same line.
So I can just put the following code in the line immediately before the mail function?
Code: Select all
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: {$recipient} <{$remail}>\r\n";
$headers .= "From: Official Mailing List <my@email.com>\r\n";
yes
feyd wrote:How would I go about creating a template that the main message fits into?
there's a multitude of ways to set it up. You can create a html page which has buttons that insert the variable text when clicked, much like the bbCode buttons found on replying to posts in this forum.
Thanks but maybe I wasn't clear... I meant that if I wanted this form to email the users but automatically format the email with some HTML around my message when it sends it, how would I go about doing that? So basically the email, when sent, would be something like:
Code: Select all
<html>
<body>
<img src="header_image_defined_in_template.jpg">
Hello John,
Here is the message I entered in the email form.
<img src="footer_image.jpg>
</body>
</html>
you can send straight html to it, it doesn't matter.. the only thing that matters about using html or plain-text is the content-type required in the headers to send html...
Posted: Sun Jul 11, 2004 10:03 pm
by furiousweebee
Ok, I'm understanding the first parts and will try them. With the last question I had, how do I "send straight html to it"? I know how to do includes so would I be able to make a HTML file and include it, with the $message variable in the middle of that page? eg
Code: Select all
<html>
<body>
<img src="header_image_defined_in_template.jpg">
Hello {first_name},
{message}
<img src="footer_image.jpg>
</body>
</html>
Posted: Sun Jul 11, 2004 10:07 pm
by feyd
yeah, use [php_man]file_get_contents[/php_man]() to extract the content of the file.. then make sure to set $row['message'] to the message you wish to send.
Posted: Sun Jul 11, 2004 10:12 pm
by furiousweebee
Would I set $row['message'] inside the page to be included, or in the main page somewhere?
lol and also, even though I went and read how to use file_get_contents(), I don't know how to format it or where to put it.
This is so confusing for a non-programmer... if you could give me examples of things where possible I'd really really appreciate it so I can see how it works before I attempt to do it myself, if that makes sense.
Thanks feyd, you've been a big help on my pitifully "simple" mission.
Posted: Sun Jul 11, 2004 10:24 pm
by feyd
using my previous code:
Code: Select all
<?php
$_POST['message'] = 'Dear {S_USALUTATION} {S_ULNAME}, {S_PMSG} and you are happily screwing around in php!';
function repData($match,$data)
{
return ( isset($data[$match]) ? $data[$match] : '{'.$match.'}' );
}
$sql = "SELECT * FROM street_team";
$query = mysql_query($sql) or die(mysql_error());
$filedata = file_get_contents('massMailTemplate_html.dat'); // return the 'massMailTemplate_html.dat's contents as a string..
while($row = mysql_fetch_assoc($query))
{
$row['message'] = $_POST['message']; // add the handle for {message} tag
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: {$row['user_name']} <{$row['user_email']}>\r\n";
$headers .= "From: Official Mailing List <my@email.com>\r\n";
$headers .= "Reply-To: Official Mailing List <my@email.com>\r\n";
$headers .= "Return-Path: Official Mailing List <my@email.com>\r\n";
mail($row['user_email'],$_POST['subject'],preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers);
}
?>
Posted: Sun Jul 11, 2004 11:06 pm
by furiousweebee
Okie dokie, thanks a lot for that. So now I could just use that code there (along with my original code) to send the email, and create a file (called massMailTemplate_html.dat) with normal HTML in it, plus tags such as {message}?
We're slowly getting there... hehe.
Posted: Sun Jul 11, 2004 11:08 pm
by feyd
yep.. you can name it whatever you want, just change the filename it looks for to whatever you want it to be..
Posted: Sun Jul 11, 2004 11:09 pm
by furiousweebee
If I go away and do this code and it works, I'm going to buy an expensive engagement ring for you.
Posted: Sun Jul 11, 2004 11:10 pm
by feyd
furiousweebee wrote:I'm going to buy an expensive engagement ring for you.

Posted: Sun Jul 11, 2004 11:24 pm
by furiousweebee
lol don't be shy.
hahaha nah I'm kidding... I'm not gay. Not that there's anything wrong with that. <--- Seinfeld.
Ok I'll stop typing here and start typing in my PHP files. *cries*