OK, hours later and much searching yields nothing....
We do newsletters on our website, they are created via a form in the backend. Currently they are generic whatever you enter in the textfield is sent and I was looking to add predefined headers and footers to them that could be edited on-the-fly. Also with that I wanted to add some variables to personalize our newsletters. (eg. Dear <#USERNAME#>...)
So basically Im trying to get the posted data analyzed and have specific "variables" replaced where relevant.
Here is the latest code I have tried....
if($_POST['action'] == "newsletter" && phpa_securepost($_POST)) {
#//
if(empty($_POST['subject']) || empty($_POST['content'])) {
$ERR = $ERR_5014;
} else {
$COUNTER = 0;
switch($_POST['usersfilter']) {
case 'test':
$query = "select email, name, nick from PHPAUCTIONXL_users where nick='sabyre'";
break;
case 'all':
$query = "select email, name, nick from PHPAUCTIONXL_users where nletter='1' and birthdate<>'99999999'";
break;
case 'active':
$query = "select email, name, nick from PHPAUCTIONXL_users where nletter='1' AND suspended=0 and birthdate<>'99999999'";
break;
case 'admin':
$query = "select email, name, nick from PHPAUCTIONXL_users where nletter='1' AND suspended=1 and birthdate<>'99999999'";
break;
case 'fee':
$query = "select email, name, nick from PHPAUCTIONXL_users where nletter='1' AND suspended=9 and birthdate<>'99999999'";
break;
case 'notconfirmed':
$query = "select email, name, nick from PHPAUCTIONXL_users where nletter='1' AND suspended=8 and birthdate<>'99999999'";
break;
case 'everyone':
$query = "select email, name, nick from PHPAUCTIONXL_users where birthdate<>'99999999'";
break;
}
$result = mysql_query($query);
$row = mysql_fetch_array($result);
//echo $content;
while($row = mysql_fetch_array($result)) {
$patterns = array();
$patterns[0] = '/<#s_nick#>/';
$replacements = array();
$replacements[0] = $row['nick'];
preg_replace($patterns,$replacements,$_POST['content']);
echo $_POST['content'];
if(mail($row['email'],stripslashes($_POST['subject']),stripslashes($_POST['content']),"From:".$SETTINGS['sitename']." <".$SETTINGS['adminmail'].">\n"."Content-Type: text/html; charset=$CHARSET")) {
$COUNTER++;
}
}
if(!$result) {
$ERR = $ERR_001;
} else {
$ERR = $COUNTER.$MSG_5300;
}
}
}
The message variables work with other areas of our site. Like if a new user signs up or someone wins an auction, but the variables are pulled from a file and are only mailed to 1 person at a time. Also we would like the info to be in the TEXTAREA so we can edit it for different newsletters.
Working Example:
$buffer = file($include_path."mail_endauction_youwin_nodutch.".$USERLANG.".inc.php");
$i = 0;
$j = 0;
while($i < count($buffer)){
if(!ereg("^#(.)*$",$buffer[$i])){
$skipped_buffer[$j] = $buffer[$i];
$j++;
}
$i++;
}
$message = implode($skipped_buffer,"");
//--Change TAGS with variables content
$message = ereg_replace("<#s_name#>",$Seller['name'],$message);
$message = ereg_replace("<#s_nick#>",$Seller['nick'],$message);
Thanks in advanced for any help with this. I know php well, but this makes me feel like a newb. Maybe i've just been on it to long...