Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Form Redirect

Status
Not open for further replies.

catalystcommercial

Technical User
Oct 6, 2005
53
GB
Hi there

I have got an HTML form which calls a PHPmailer script, I want to redirect to a thankyou page after the form submission, can you tell me how to put this in my PHP script?

Thanks

Tim
 
insert this after you have tested for success of the form mailer.

Code:
$targetpage = "[URL unfurl="true"]http://www.somedomain.com/somepage.php";[/URL]
header("Location:".$targetpage);
 
Hi jpadie

I have entered the code at the end of the script but I get the error

Your data has been recorded successfully! Warning: Cannot modify header information - headers already sent by (output started at /home/catalyst/public_html/cheese/PHPMailer.php:8) in /home/catalyst/public_html/cheese/PHPMailer.php on line 306

Any ideas?
 
this happens if you have already sent output to the browser before the header call. any output at all triggers this error. even a carriage return/blank line.

 
that's a bit difficult without your code. it's not a question of "where" you put it but that you must not put anything that creates an output before the line.

for example
Code:
<!-- blank line -->
<?
header ("Location: somepage.php"); 
?>

this will fail because there is some html that is being sent to the browser. it's just a blank line but will still fail.

if you can't spot what might be causing the earlier output (and usually php will tell you the line reference) then by all means post the script.
 
Hi Jpadie

This is my PHP script where I want to redirect from

<html>
<head>
<title>PHP Mail from GoldMine</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
/******************************************************
*******************************************************
** PHPMailer.php
** written by JCS
** Purpose:
** This script was generated
** with the GoldMine Web Import
** script generator. It will generate
** the INI style of web import data
** and email the results to the contact
** entered in the tool.
**
** WARNING: This script requires that you
** have proper setup of your Apache server to
** A. use PHP
** B. setup of your PHP mailer for your SMTP data.
*******************************************************
*******************************************************
*/
function Decode($strValueIn)
{
//Do not modify this function!
$intX = 0;
$intY = 0;
$Temp = "";
$Mod = "";
$intMod =0;
$intTemp = 0;
$ValueOut = "";
$intY = 1;
$strValueOut="";
for ($intX=1; $intX<=((strlen($strValueIn)/2)/2); $intX=$intX+1)
{

$strTemp="";
$strMod="";
if (($intX % 2)==0)
{

$strMod=substr(substr($strValueIn,$intY-1,4),0,2);
$strTemp=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2));
}
else
{

$strMod=substr(substr($strValueIn,$intY-1,4),strlen(substr($strValueIn,$intY-1,4))-(2));
$strTemp=substr(substr($strValueIn,$intY-1,4),0,2);
}

$intMod=hexdec($strMod);
$intTemp=hexdec($strTemp);
$intTemp=$intTemp-$intMod;
$strValueOut=$strValueOut.chr($intTemp);
$intY=$intY+4;

}

return $strValueOut;



}

if ($_POST["GMsubmit"]!="")
{
$Body = "";
//$SendToEmail = Decode($_POST["SendToEmail"]);
//$SMTP = Decode($_POST["SMTP"]); //Your SMTP data may have to be set set on the Apache Server, and this variable is not used.
$OnNewSendGMEmail = $_POST["OnNewSendGMEmail"];
if ($OnNewSendGMEmail!="")
{$OnNewSendGMEmail = Decode($OnNewSendGMEmail);}
else
{$OnNewSendGMEmail = "";}

if ($_POST["OnDUPSendGMEmail"]!="")
{$OnDUPSendGMEmail = Decode($_POST["OnDUPSendGMEmail"]);}
else
{$OnDUPSendGMEmail = "";}
if ($_POST["OnNewAttachTrack"]!="")
{$OnNewAttachTrack = Decode($_POST["OnNewAttachTrack"]);}
else
{$OnNewAttachTrack = "";}
if ($_POST["OnDupAttachTrack"]!="")
{$OnDupAttachTrack = Decode($_POST["OnDupAttachTrack"]);}
else
{$OnDupAttachTrack = "";}
if ($_POST["Word"]!="")
{$Password = Decode($_POST["Word"]);}
else
{$Password = "";}
if ($_POST["DupLogic"]!="")
{$DupLogic = Decode($_POST["DupLogic"]);}
else
{$DupLogic = "";}

$OutputAs = $_POST["OutPutAs"];
$DuplicateCount=0;
$XML = "<gmdata>";

if ($_POST["DuplicateCount"]!="")
{
$DuplicateCount =intval($_POST["DuplicateCount"]);

}
if ($DuplicateCount >0 || $OnNewSendGMEmail!="" || $OnDUPSendGMEmail!="" ||
$OnNewAttachTrack!="" || $OnDupAttachTrack!="")
{
$Body = $Body."[Instructions]\n";
$XML = $XML."<Instructions>";
if ($DuplicateCount > 0)
{
for($counter=0; $counter < $DuplicateCount; $counter++)
{
$RealCount=$counter+1;
$str = "DuplicateChecking$RealCount";
eval("\$str = \"$str\";");
$Body = $Body."DupCheck".$RealCount."=".$_POST[$str]."\n";
//print($str.":".$_POST[$str].";");
$tempVal = $_POST[$str];
if ($tempVal==="EMAIL")
{
$XML = $XML."<DupCheck>EA1</DupCheck>";
}
else
{
if ($tempVal==="WEBSITE")
{
$XML = $XML."<DupCheck>WS1</DupCheck>";
}
else
{
$XML = $XML."<DupCheck>".htmlspecialchars($_POST[$str])."</DupCheck>";
}
}
}
if ($DupLogic !="")
{$Body = $Body."DupLogic=OR\n";}
}
if ($OnNewSendGMEmail!="")
{
$Body = $Body."OnNewSendGMEmail=".$OnNewSendGMEmail."\n";
$XML = $XML."<OnNewSendGMEmail>".htmlspecialchars($OnNewSendGMEmail)."</OnNewSendGMEmail>";

}
if ($OnDUPSendGMEmail!="")
{
$Body = $Body."OnDUPSendGMEmail=".$OnDUPSendGMEmail."\n";
$XML = $XML."<OnDupSendGMEmail>".htmlspecialchars($OnDUPSendGMEmail)."</OnDupSendGMEmail>";

}
if ($OnNewAttachTrack!="")
{
$comma =strpos($OnNewAttachTrack, ",");
$Body = $Body."OnNewAttachTrack=".$OnNewAttachTrack."\n";
if ($comma =="")
{
$XML = $XML."<OnNewAttachTrack>".htmlspecialchars($OnNewAttachTrack)."</OnNewAttachTrack>";
}
else
{
list($track, $user) = split(',', $OnNewAttachTrack,2);
$XML = $XML."<OnNewAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnNewAttachTrack>";
}
}
if ($OnDupAttachTrack!="")
{
$comma =strpos($OnDupAttachTrack, ",");
$Body = $Body."OnDupAttachTrack=".$OnDupAttachTrack."\n";
if ($comma =="")
{
$XML = $XML."<OnDupAttachTrack>".htmlspecialchars($OnDupAttachTrack)."</OnDupAttachTrack>";
}
else
{
list($track, $user) = split(',', $OnDupAttachTrack,2);
$XML = $XML."<OnDupAttachTrack User=".chr(34).htmlspecialchars($user).chr(34).">".htmlspecialchars($track)."</OnDupAttachTrack>";
}


}
if ($Password!="")
{
$Body = $Body."Password=".$Password."\n";
$XML = $XML."<Password>".htmlspecialchars($Password)."</Password>";

}
if ($DupLogic!="")
{
$XML = $XML."<DupLogic>OR</DupLogic>";
}
else
{
$XML = $XML."<DupLogic>AND</DupLogic>";
}

$XML = $XML."</Instructions>";
}
$Body = $Body."[Data]\n";
$XML = $XML."<accounts><account>";
$Phone = "";
$EA = "";
$WS = "";
$PR = "";
while(list($key,$value)= each($_POST))
{
eval("$\$key = \"$value\";");


{

if ($key!="GMsubmit" && $key!="SMTP" && $key!="OnNewSendGMEmail" &&
$key!="OnDUPSendGMEmail" && $key!="OnNewAttachTrack" &&
$key!="OnDupAttachTrack" && $key!="SendToEmail" && $key!="DuplicateCount" && $key!="Word" &&
strpos($key, "DuplicateChecking") === false && $key!="OutPutAs" && $key!="DupLogic" && strpos($key, "pretty_") === false)

{


if($value!="")
{
$Body = $Body.$key."=".$value."\n";
if (substr($key,0,5)!="PHONE" && substr($key,0,3)!="FAX" && substr($key, 0, 5)!="EMAIL" && substr($key,0, 7)!="WEBSITE")

{

$PR = $PR."<property name=".chr(34).$key.chr(34)." db_name=".chr(34).$key.chr(34).">";
$PR = $PR."<property_string>".htmlspecialchars($value)."</property_string>";
$PR = $PR."</property>";
}
else
{
if(substr($key,0,5)=="PHONE")
{

$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">";
$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>";
$Phone = $Phone."</phone>";
}
elseif(substr($key,0,3)=="FAX")
{
$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$key.chr(34)." source_fld=".chr(34).$key.chr(34).">";
$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$value."</property_string></property></properties>";
$Phone = $Phone."</phone>";
}
elseif(substr($key,0,7)=="WEBSITE")
{
$WS = $WS."<website primary=".chr(34)."1".chr(34)." id=".chr(34)."WS1".chr(34).">";
$WS = $WS."<properties><property name=".chr(34)."web_site".chr(34)."><property_string>".$value."</property_string></property></properties>";
$WS = $WS."</website>";
}
elseif(substr($key,0,5)=="EMAIL")
{
$EA = $EA."<email primary=".chr(34)."1".chr(34)." id=".chr(34)."EA1".chr(34).">";
$EA = $EA."<properties><property name=".chr(34)."email_address".chr(34)."><property_string>".$value."</property_string></property></properties>";
$EA = $EA."</email>";
}

}
}

}
}

}
if ($PR !="")
{$XML = $XML."<properties>".$PR."</properties>";}
if($Phone!="")
{
$XML = $XML."<phone_numbers>".$Phone."</phone_numbers>";
}
if($EA!="")
{
$XML = $XML."<emails>".$EA."</emails>";
}
if($WS!="")
{
$XML = $XML."<websites>".$WS."</websites>";
}
$XML = $XML."</account></accounts></gmdata>";
$ToSubject="Web Import";

//The PHP built in function mail() will not raise or cause errors if it fails - so be sure that your PHP server is setup correctly!
if( $OutputAs!="INI")
{
$Body = $XML;
}
ini_set("SMTP", Decode($SMTP));
if(mail(Decode($SendToEmail), $ToSubject, $Body, "From: GoldMine WebImport <no-reply@frontrange.com>\r\nContent-Type: text/x-gm-impdata\r\n" )) {

print "Your data has been recorded successfully!\n\n<!--\n".Decode($SendToEmail)."\n".$ToSubject."\n".$Body."\n\n".$OutputAs."\n\n-->";
}
else
{print("There was a mailer failure.\n\n<!--\n".$Body."\n\n-->");}
}
else
{echo "There was no form data passed.";}
?>
</body>
</html>

 
delete all the html before the <?php. the header redirect code goes instead of this line
Code:
print "Your data has been recorded successfully!\n\n<!--\n".Decode($SendToEmail)."\n".$ToSubject."\n".$Body."\n\n".$OutputAs."\n\n-->";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top