Extremely Simple Mailing List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

I'll take the ring..











..then sell it on ebay for a CPU/Video card :)
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

Heartbreaker!!! :'(
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

furiousweebee wrote: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}?
Ok, so here's what I have now:

Code: Select all

<?php
include('db.php');

$form['mail'] = '
<form action="?act=mail" method="post">
<input type="hidden" name="send" value="yes">
	<table>
	<tr>	
	<td>Subject:</td>
	<td><input type="text" name="subject" value="Mailing List" cols="70" size="65"></td>
	</tr>
	<tr>
	<td valign="top">Email Message:</td>
	<td><textarea name="message" rows="15" cols="50"></textarea></td>
	</tr>
	<tr>
	<td>&nbsp;</td>
	<td><input type="submit" value="Send To The Mailing List"></td>
	</tr>
	</table>
</form>
';

$admin_forms = '';
switch (@$_GET['act']){

case 'mail':
if (!connect_db()){
	$admin_forms = 'Error connecting to database, '.mysql_error().'.';
} else {
$res = mysql_query("SELECT email FROM mailing_list", $mysql_conn);
$filedata = file_get_contents('template.html');

if (@$_POST['send'] == 'yes'){
	while ($row = mysql_fetch_assoc($res)){
	$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: Fans <{$row['email']}>\r\n"; 
  	$headers .= "From: Mailing List <mailinglist@site.com>\r\n"; 
  	$headers .= "Reply-To: Mailing List <mailinglist@site.com>\r\n"; 
  	$headers .= "Return-Path: Mailing List <mailinglist@site.com>\r\n";
	$admin_forms .= mail($row['email'], $_POST['subject'], stripslashes($_POST['message']), preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers)?

'Email to '.$row['email'].' was successful.<br>':
'<strong>Email to '.$row['email'].' has failed.</strong><br>';
	}
}
}

break;

case 'logout':
	header("Location: ../index.php");
	break;

default:
	$admin_forms = $form['mail'].'<a href="?act=logout">Log Out</a>';
}
?>
My HTML template page contains the following:

Code: Select all

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;mail template&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;
Howdy,&lt;br&gt;&lt;br&gt;

&#123;message&#125;&lt;br&gt;&lt;br&gt;

Thanks!
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
My problem is two-fold:

1. The template doesn't appear to be used, as only the message entered in my email form gets sent (no "Howdy" etc from the template); and

2. Regardless of what I set the From: address to, it sends the email from myhostingaccountusername@mydomain.com

Any ideas on those things?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$admin_forms .= mail($row&#1111;'email'], $_POST&#1111;'subject'], stripslashes($_POST&#1111;'message']), preg_replace('#\&#123;(&#1111;^\&#125;]+?\&#125;#e','repData("\\1",$row)',$filedata),$headers)?
looks like it'd be the problem... I think you want to pull your "stripslashes($_POST['message'])"
mail() wrote:bool mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]])
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

I did that but it had no effect. I notice there's no comma after "string message" in the mail() syntax you just showed me. Might this have something to do with it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what's the line look like now?
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

Originally:

Code: Select all

$admin_forms .= mail($row['email'], $_POST['subject'], stripslashes($_POST['message']), preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers)?
Now:

Code: Select all

$admin_forms .= mail($row['email'], $_POST['subject'], $_POST['message'], preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers)?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$admin_forms .= mail($row['email'], $_POST['subject'], preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers);
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

Hmm, now the page doesn't load... it's completely blank.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

oops.. switch the semicolon for a question mark.. I didn't notice the rest of the ternary after it before :)
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

That worked with loading the form, but the email was completely blank. The other remaining problem is that it emails me twice when I'm only in the mailing_list table once.
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

Any other ideas man?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try echoing the result of the preg_replace.. the double email may be from the $headers having To in it.. not sure.. check the details of the email you got..
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

I'm not sure how to echo that. :oops:

I had already commented out the To: part but it was still sending duplicates. Here's what I have now:

Code: Select all

<?PHP
$res = mysql_query("SELECT email FROM mailing_list", $mysql_conn);
	$filedata = file_get_contents('template.html');
	if (@$_POST['send'] == 'yes'){
		while ($row = mysql_fetch_assoc($res)){
		$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 .= "From: Ten Foot Pole Mailing List <band@tenfootpole.com>\r\n"; 
		$headers .= "Return-Path: Ten Foot Pole Mailing List <band@tenfootpole.com>\r\n";
		$admin_forms .= mail($row['email'], $_POST['subject'], preg_replace('#\{([^\}]+?\}#e','repData("\\1",$row)',$filedata),$headers)?
		'Email to '.$row['email'].' was successful.<br>':
		'<strong>Email to '.$row['email'].' has failed.</strong><br>';
				}
			}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

example

Code: Select all

$msg = preg_replace(.......);
mail($row['email'],$_POST['subject'],$msg,$headers)? // blah blah blah
Post Reply