lrickyutah
03-22-2009, 04:29 AM
Hi there,
I have this heavily edited script I've been playing with to allow site visitors to suggest the site to multiple people.
I'd like to insert some HTML into the email that is sent in the recommendation email. Is that even possible?
and maybe a bcc, so that I can tell when the form is being used?
Here's the code . . .
<?php
$thisprog = "pbltellafriend2.php";
$template = "template2.html"; // must be valid!
$people = "5"; // number of people user can recommend page to at a time
$fontface = "Arial"; // font style
$fontsize = "11"; // size in points! (pt); NOT html sizes, a decent size is between 8-14
$fontcolor = "#000";
$maxlength = "50"; // maximum length of string displayed url will be before adding "..." before it
$messagefile = "tellafriend_message.txt"; // does not need to be modified if file exists in same directory
$mes_footer_file = "tellafriend_mes_footer.txt"; // does not need to be modified if file exists in same directory
$subject = "TEST MESSAGE"; // change this to your default subject
$changesub = "n"; // allow users to change the "subject" of the email
$requirerefer = "n"; // y or n
$validservers = "pixelatedbylev.com,www.pixelatedbylev.com,taintedthoughts.com,www.taintedthoughts.com";
$uselog = "n"; // want to enable log recording so that you may view a log of recommendations? ***REQUIRES mySQL!***
$validemail = "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
$program = 'Tell A Friend v 1.11'; // do not change
$programnoversion = preg_replace("/^(.*?) v (.*?)$/","\\1",$program);
$data .= "<FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize" . "pt;COLOR:$fontcolor;\">\n";
if ($_POST['process'] && $_POST['url'] && $_POST['name'] != '' && preg_match($validemail,$_POST['email']))
{
$title = "Recommend Site";
if ($requirerefer == 'y')
{
$validarray = explode(",",$validservers);
foreach ($validarray as $valid)
{
if (ereg($valid,$_POST['url']))
{
$serverisvalid = 'y';
}
}
}
if ($serverisvalid != 'y' && $requirerefer == 'y') {$data .= "THIS SERVER IS NOT PERMITTED TO BE RECOMMENDED!";}
elseif ($serverisvalid == 'y' || $serverisvalid == '')
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: " . $_POST['name'] . " <" . $_POST['email'] . ">\r\n";
$headers .= "Reply-to: " . $_POST['name'] . " <" . $_POST['email'] . ">\r\n";
if (file_exists($mes_footer_file))
{
$fh = fopen ($mes_footer_file,"r");
$eml_footer_data = fread($fh,filesize($mes_footer_file));
fclose ($fh);
}
if ($_POST['subject'] != '')
{
$subjecttouse = $_POST['subject'];
}
else
{
$subjecttouse = $GLOBALS['subject'];
$data .= "<font color=\"#000000\">Thank you, your message has been sent to:</font>\n<br>\n\n<br>\n";
}
$emailedusers = '0';
for ($i=1;$i <= $people;$i++)
{
if (preg_match($validemail,$_POST["email$i"]))
{
$emailedusers++;
stripslashes($_POST['message']);
if ($eml_footer_data != '')
{
$newmessage = $_POST['message'] . "\n\n" . $eml_footer_data;
}
else
{
$newmessage = $_POST['message'];
}
mail ($_POST["email$i"],$subjecttouse,$newmessage,$headers);
if ($uselog == 'y') {$query = log_to_db ($_POST["email$i"]);}
$data .= "<font color=\"#000000\">• " . $_POST["email$i"] . "</font>\n";
}
}
if ($emailedusers == '0') {$data .= "<font color=\"#990000\"><i><b>Error:</b></i> you need to enter at least one email address.</font>\n<BR>\n\n<BR>\n<a href=\"javascript: history.go(-1)\">go back</a>";}
}
$data .= "<P>";
}
elseif ($_GET['action'] == '')
{
$title = "Recommend Site";
if ($_GET['url'] != '')
{
$url = $_GET['url'];
$url = str_replace("~!Q!~","?",$url);
$url = str_replace("~!AMP!~","&",$url);
}
elseif ($_POST['url'] != '')
{
$url = $_POST['url'];
}
elseif ($_SERVER['HTTP_REFERER'] != '')
{
$url = $_SERVER['HTTP_REFERER'];
}
else
{
$url = "http://" . $_SERVER['SERVER_NAME'];
}
if ($length = strlen($url) > $maxlength)
{
$start = strlen($url) - $maxlength;
$end = strlen($url);
$url2 = "..." . substr($url,$start,$end);
}
else
{
$url2 = $url;
}
if ($_POST['message'] == '')
{
$fh = fopen($messagefile,"r");
$message = fread ($fh,filesize($messagefile));
fclose ($fh);
$message = str_replace('$url',$url,$message);
}
else
{
$message = $_POST['message'];
}
if ($_POST['name'] == '' || !preg_match($validemail,$_POST['email']))
{
$data .= "<P>\n";
}
$data .= "<FORM ACTION=$thisprog METHOD=POST>\n";
$data .= "<TABLE WIDTH=\"100%\">\n";
$data .= "<INPUT TYPE=HIDDEN NAME=process VALUE=y><INPUT TYPE=HIDDEN NAME=url VALUE=\"" . $url . "\">\n";
$data .= "<TR><TD align=\"LEFT\" valign=\"BOTTOM\">Your Name: </td><td align=\"LEFT\" valign=\"BOTTOM\"><INPUT TYPE=TEXT NAME=name SIZE=20 VALUE=\"" . $_POST['name'] . "\"></TD></TR>\n";
$data .= "<TR><TD align=\"LEFT\" valign=\"BOTTOM\">Your Email: </td><td align=\"LEFT\" valign=\"BOTTOM\"><INPUT TYPE=TEXT NAME=email SIZE=20 VALUE=\"" . $_POST['email'] . "\"></TD></TR>\n";
$data .= "<TR><TD COLSPAN=\"2\"><TABLE WIDTH=\"100%\" style=\"padding-bottom:15px; PADDING-TOP:15PX;\"><TR><TD>Name:</TD><TD>Email:</TD></TR>\n";
for ($i=1;$i <= $people;$i++)
{
$data .= "<TR><TD><INPUT TYPE=TEXT NAME=first$i SIZE=15 VALUE=\"" . $_POST["first$i"] . "\"></TD><TD><INPUT TYPE=TEXT NAME=email$i SIZE=20 VALUE=\"" . $_POST["email$i"] . "\"></TD></TR>\n";
}
$data .= "</TABLE></TD></TR><TR><TD COLSPAN=\"2\">Please enter a note for your colleagues below:<br><TEXTAREA ROWS=5 COLS=30 NAME=\"message\">$message</TEXTAREA></TD></TR>\n";
$data .= "</TABLE>\n<P>\n";
$data .= "<INPUT TYPE=SUBMIT VALUE=\"Send\"> <input type=reset value=\"Reset\">\n</FORM>\n";
}
$data .= "\n<FONT SIZE=1>$footer</FONT></BLOCKQUOTE>\n";
$data = str_replace('$title',$title,$data);
printpage($title,$data,"");
function log_to_db ($email)
{
$time = time();
if ($_POST['subject'] != '')
{
$subjecttouse = $_POST['subject'];
}
else
{
$subjecttouse = $GLOBALS['subject'];
}
mysql_connect ($GLOBALS['sqlhost'], $GLOBALS['sqluser'], $GLOBALS['sqlpass']);
mysql_select_db ($GLOBALS['sqldbnm']);
$query = "INSERT INTO `recommend_log` (`time`,`name`,`email`,`subject`,`message`,`to`,`ip`) VALUES ('$time', '" . $_POST['name'];
$query .= "', '" . $_POST['email'] . "', '" . $subjecttouse . "', '" . $_POST['message'] . "', '$email', '";
$query .= $_SERVER['REMOTE_ADDR'] . "');";
if (mysql_query($query)) {return "SUCCESSFUL TO LOG";} else {return "FAILED TO LOG";}
}
function printpage ($title,$data,$meta)
{
$newtitle = $GLOBALS['program'] . " -> " . $title;
$fh = fopen ($GLOBALS['template'],"r");
$template = fread($fh,filesize($GLOBALS['template']));
fclose ($fh);
$newdata = str_replace('$title',$newtitle,$template);
$newdata = str_replace('$meta',$meta,$newdata);
$newdata = str_replace('$data',$data,$newdata);
echo $newdata;
}
?>
The test site is here . . . http://chs99.org/test/pbltellafriend2.php
I have this heavily edited script I've been playing with to allow site visitors to suggest the site to multiple people.
I'd like to insert some HTML into the email that is sent in the recommendation email. Is that even possible?
and maybe a bcc, so that I can tell when the form is being used?
Here's the code . . .
<?php
$thisprog = "pbltellafriend2.php";
$template = "template2.html"; // must be valid!
$people = "5"; // number of people user can recommend page to at a time
$fontface = "Arial"; // font style
$fontsize = "11"; // size in points! (pt); NOT html sizes, a decent size is between 8-14
$fontcolor = "#000";
$maxlength = "50"; // maximum length of string displayed url will be before adding "..." before it
$messagefile = "tellafriend_message.txt"; // does not need to be modified if file exists in same directory
$mes_footer_file = "tellafriend_mes_footer.txt"; // does not need to be modified if file exists in same directory
$subject = "TEST MESSAGE"; // change this to your default subject
$changesub = "n"; // allow users to change the "subject" of the email
$requirerefer = "n"; // y or n
$validservers = "pixelatedbylev.com,www.pixelatedbylev.com,taintedthoughts.com,www.taintedthoughts.com";
$uselog = "n"; // want to enable log recording so that you may view a log of recommendations? ***REQUIRES mySQL!***
$validemail = "/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/";
$program = 'Tell A Friend v 1.11'; // do not change
$programnoversion = preg_replace("/^(.*?) v (.*?)$/","\\1",$program);
$data .= "<FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize" . "pt;COLOR:$fontcolor;\">\n";
if ($_POST['process'] && $_POST['url'] && $_POST['name'] != '' && preg_match($validemail,$_POST['email']))
{
$title = "Recommend Site";
if ($requirerefer == 'y')
{
$validarray = explode(",",$validservers);
foreach ($validarray as $valid)
{
if (ereg($valid,$_POST['url']))
{
$serverisvalid = 'y';
}
}
}
if ($serverisvalid != 'y' && $requirerefer == 'y') {$data .= "THIS SERVER IS NOT PERMITTED TO BE RECOMMENDED!";}
elseif ($serverisvalid == 'y' || $serverisvalid == '')
{
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: " . $_POST['name'] . " <" . $_POST['email'] . ">\r\n";
$headers .= "Reply-to: " . $_POST['name'] . " <" . $_POST['email'] . ">\r\n";
if (file_exists($mes_footer_file))
{
$fh = fopen ($mes_footer_file,"r");
$eml_footer_data = fread($fh,filesize($mes_footer_file));
fclose ($fh);
}
if ($_POST['subject'] != '')
{
$subjecttouse = $_POST['subject'];
}
else
{
$subjecttouse = $GLOBALS['subject'];
$data .= "<font color=\"#000000\">Thank you, your message has been sent to:</font>\n<br>\n\n<br>\n";
}
$emailedusers = '0';
for ($i=1;$i <= $people;$i++)
{
if (preg_match($validemail,$_POST["email$i"]))
{
$emailedusers++;
stripslashes($_POST['message']);
if ($eml_footer_data != '')
{
$newmessage = $_POST['message'] . "\n\n" . $eml_footer_data;
}
else
{
$newmessage = $_POST['message'];
}
mail ($_POST["email$i"],$subjecttouse,$newmessage,$headers);
if ($uselog == 'y') {$query = log_to_db ($_POST["email$i"]);}
$data .= "<font color=\"#000000\">• " . $_POST["email$i"] . "</font>\n";
}
}
if ($emailedusers == '0') {$data .= "<font color=\"#990000\"><i><b>Error:</b></i> you need to enter at least one email address.</font>\n<BR>\n\n<BR>\n<a href=\"javascript: history.go(-1)\">go back</a>";}
}
$data .= "<P>";
}
elseif ($_GET['action'] == '')
{
$title = "Recommend Site";
if ($_GET['url'] != '')
{
$url = $_GET['url'];
$url = str_replace("~!Q!~","?",$url);
$url = str_replace("~!AMP!~","&",$url);
}
elseif ($_POST['url'] != '')
{
$url = $_POST['url'];
}
elseif ($_SERVER['HTTP_REFERER'] != '')
{
$url = $_SERVER['HTTP_REFERER'];
}
else
{
$url = "http://" . $_SERVER['SERVER_NAME'];
}
if ($length = strlen($url) > $maxlength)
{
$start = strlen($url) - $maxlength;
$end = strlen($url);
$url2 = "..." . substr($url,$start,$end);
}
else
{
$url2 = $url;
}
if ($_POST['message'] == '')
{
$fh = fopen($messagefile,"r");
$message = fread ($fh,filesize($messagefile));
fclose ($fh);
$message = str_replace('$url',$url,$message);
}
else
{
$message = $_POST['message'];
}
if ($_POST['name'] == '' || !preg_match($validemail,$_POST['email']))
{
$data .= "<P>\n";
}
$data .= "<FORM ACTION=$thisprog METHOD=POST>\n";
$data .= "<TABLE WIDTH=\"100%\">\n";
$data .= "<INPUT TYPE=HIDDEN NAME=process VALUE=y><INPUT TYPE=HIDDEN NAME=url VALUE=\"" . $url . "\">\n";
$data .= "<TR><TD align=\"LEFT\" valign=\"BOTTOM\">Your Name: </td><td align=\"LEFT\" valign=\"BOTTOM\"><INPUT TYPE=TEXT NAME=name SIZE=20 VALUE=\"" . $_POST['name'] . "\"></TD></TR>\n";
$data .= "<TR><TD align=\"LEFT\" valign=\"BOTTOM\">Your Email: </td><td align=\"LEFT\" valign=\"BOTTOM\"><INPUT TYPE=TEXT NAME=email SIZE=20 VALUE=\"" . $_POST['email'] . "\"></TD></TR>\n";
$data .= "<TR><TD COLSPAN=\"2\"><TABLE WIDTH=\"100%\" style=\"padding-bottom:15px; PADDING-TOP:15PX;\"><TR><TD>Name:</TD><TD>Email:</TD></TR>\n";
for ($i=1;$i <= $people;$i++)
{
$data .= "<TR><TD><INPUT TYPE=TEXT NAME=first$i SIZE=15 VALUE=\"" . $_POST["first$i"] . "\"></TD><TD><INPUT TYPE=TEXT NAME=email$i SIZE=20 VALUE=\"" . $_POST["email$i"] . "\"></TD></TR>\n";
}
$data .= "</TABLE></TD></TR><TR><TD COLSPAN=\"2\">Please enter a note for your colleagues below:<br><TEXTAREA ROWS=5 COLS=30 NAME=\"message\">$message</TEXTAREA></TD></TR>\n";
$data .= "</TABLE>\n<P>\n";
$data .= "<INPUT TYPE=SUBMIT VALUE=\"Send\"> <input type=reset value=\"Reset\">\n</FORM>\n";
}
$data .= "\n<FONT SIZE=1>$footer</FONT></BLOCKQUOTE>\n";
$data = str_replace('$title',$title,$data);
printpage($title,$data,"");
function log_to_db ($email)
{
$time = time();
if ($_POST['subject'] != '')
{
$subjecttouse = $_POST['subject'];
}
else
{
$subjecttouse = $GLOBALS['subject'];
}
mysql_connect ($GLOBALS['sqlhost'], $GLOBALS['sqluser'], $GLOBALS['sqlpass']);
mysql_select_db ($GLOBALS['sqldbnm']);
$query = "INSERT INTO `recommend_log` (`time`,`name`,`email`,`subject`,`message`,`to`,`ip`) VALUES ('$time', '" . $_POST['name'];
$query .= "', '" . $_POST['email'] . "', '" . $subjecttouse . "', '" . $_POST['message'] . "', '$email', '";
$query .= $_SERVER['REMOTE_ADDR'] . "');";
if (mysql_query($query)) {return "SUCCESSFUL TO LOG";} else {return "FAILED TO LOG";}
}
function printpage ($title,$data,$meta)
{
$newtitle = $GLOBALS['program'] . " -> " . $title;
$fh = fopen ($GLOBALS['template'],"r");
$template = fread($fh,filesize($GLOBALS['template']));
fclose ($fh);
$newdata = str_replace('$title',$newtitle,$template);
$newdata = str_replace('$meta',$meta,$newdata);
$newdata = str_replace('$data',$data,$newdata);
echo $newdata;
}
?>
The test site is here . . . http://chs99.org/test/pbltellafriend2.php