Log in

View Full Version : Resolved Editing the "Thanks" message after submit.



lrickyutah
03-19-2009, 10:27 PM
I've found a piece of code that I've heavily edited to work on my site and I'm almost there!

Is there anything I can add in the php to have a "Thanks for submitting . . ." message?

Here's the code . . . (I've used the free code from pixelatedbylev.com and edited it heavily to work for me.)


<?php


$thisprog = "pbltellafriend.php";
$template = "template.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";
$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!***

// IF YOU WANTED TO ENABLE LOG RECORDING THEM THE FOLLOWING PARAMETERS ALSO MUST BE SET

$truepassword = "pbl"; // password you will use in url query string to access log data

// MYSQL REQUIRED PARAMETERS
$GLOBALS['sqlhost'] = 'localhost';
$GLOBALS['sqluser'] = 'username';
$GLOBALS['sqlpass'] = 'password';
$GLOBALS['sqldbnm'] = 'database_name';


$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";

$footer = get_footer();

if ($_GET['action'] == 'auto-update')
{
list ($tempprog,$version) = split (" v ",$program);
$tempprog = str_replace(" ","_",$tempprog);
header ("Location: http://www.pixelatedbylev.com/au.php?p=$tempprog&v=$version");
exit;
}

if ($_GET['action'] == 'log' && $_GET['password'] == $truepassword)
{
$title = "Log";
mysql_connect ($GLOBALS['sqlhost'], $GLOBALS['sqluser'], $GLOBALS['sqlpass']);
mysql_select_db ($GLOBALS['sqldbnm']);
$data .= "attempting to read from mySQL database...<P>\n";
$query = "SELECT * FROM `recommend_log` ORDER BY `time` DESC";
if ($result = mysql_query($query))
{
$data .= "<CENTER><TABLE CELLSPACING=0 CELLPADDING=3 BORDER=1>";
$total = mysql_num_rows($result);
while ($logrow = mysql_fetch_array($result))
{
$logrow['message'] = str_replace("\n","<BR>",$logrow['message']);
$newtime = date("g:ia d M. Y",$logrow['time']);
$data .= "<TR><TD><FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize" . "pt;COLOR:$fontcolor;\"><B>From:</B><BR>" . $logrow['name'] . "\n<BR>\n" . $logrow['email'];
$data .= "\n<BR>\n" . $logrow['ip'] . "<P>\n<B>To:</B>\n<BR>\n" . $logrow['to'] . "<P>\n";
$data .= "<B>Time:</B>\n<BR>\n" . $newtime . "</FONT></TD><TD>";
$data .= "<FONT STYLE=\"FONT-FAMILY:$fontface;FONT-SIZE:$fontsize" . "pt;COLOR:$fontcolor;\"><B>" . $logrow['subject'] . "</B><P>" . $logrow['message'] . "</TD>";
}
$data .= "</TABLE></CENTER><P>SUCCESSFULLY READ LOG DATA (<B>$total</B> records!)!<P>\n";
}
else
{
$createq = "CREATE TABLE `recommend_log` (
`time` INT( 15 ) NOT NULL ,
`name` TEXT NOT NULL ,
`email` TEXT NOT NULL ,
`subject` TEXT NOT NULL ,
`message` MEDIUMTEXT NOT NULL ,
`to` TEXT NOT NULL ,
`ip` TEXT NOT NULL
);";
if ($createres = mysql_query($createq))
{
$data .= "FAILED TO READ DATA; SUCCESSFULLY CREATED NEW TABLE IN DATABASE!<P>\n";
}
else
{
$data .= "FAILED TO READ OR CREATE FROM mySQL DATABASE!<P>\n";
}
}
}

if ($footer == '' || !ereg("www.pixelatedbylev.com",$footer) || !ereg("$program",$footer) || !ereg("Tell A Friend",$footer))
{
header("Location: http://www.pixelatedbylev.com/footer.php");
exit;
}



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'];
}
$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 .= "recommended <I>" . $_POST["email$i"] . "</I> successfully!\n<BR>\n";
}
}
if ($emailedusers == '0') {$data .= "you need to enter one or more email addresses to recommend!\n<BR>\n";}
}
$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";
if (!ereg($footer,$data))
{
header ("Location: http://www.pixelatedbylev.com/footer.php");
exit;
}
$data = str_replace('$title',$title,$data);
printpage($title,$data,"");


function get_footer ()
{
$data = "\n\n<P><FONT STYLE=\"FONT-FAMILY:" . $GLOBALS['fontface'] . ";FONT-SIZE:" . ($GLOBALS['fontsize'] - 2) . "pt;COLOR:" . $GLOBALS['fontcolor'] . ";\">Powered by <A HREF=\"http://www.pixelatedbylev.com\" STYLE=\"color:$GLOBALS[fontcolor]\" TARGET=\"_top\">" . $GLOBALS['program'] . "</A>!</SMALL>";
return $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;
}
?>

tgallagher26
03-20-2009, 03:31 PM
Whats the link to the page this is on?

Tim..

AdrielGreene
03-20-2009, 07:30 PM
Make an if else associated with a function with checks for failures. Here is an example with a mail() function which worked well on my site.


$ok = @mail($email_to, $email_subject, $email_message, $headers);

if($ok) {
echo "Your sample has been submitted to your practitioner.
Click <a href=\"#\" onclick=\"history.back();\">here</a> to return.";

} else {
fail("Sorry but the email could not be sent. Please try again.");
}

It wont work with all functions, but it might work for you. Hope this helps.

lrickyutah
03-21-2009, 06:05 AM
Whats the link to the page this is on?

Tim..

It looks like I may have it working. I took out a lot of the superfluous code I didn't need.

Here's the new 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\">&bull;&nbsp;" . $_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;
}



?>

http://chs99.org/test/pbltellafriend2.php

It works great.