in php:
[code=php]
<?php
$fruitlink =”;
$thankyou = ‘thankyou.html’; // required
$mailfrom = ‘[email protected]’; // required
$mailcopy = ‘[email protected]’; // optional
$mailsubj = ‘Received Email’; // required
$cr = “r”; // carriage-return character
$lf = “n”; // line-feed character
$lterm = $cr.$lf; // headers and body line terminator for email
$messages = ”; // form fields error messages
$fruit = ”; // fruit field
if($fruit == “apples”):
$fruitlink = ‘http://www.yahoo.com’;
elseif($fruit == “oranges”):
$fruitlink = ‘http://www.msn.com’;
elseif($fruit == “grapes”):
$fruitlink = ‘http://microsoftcom’;
endif;
// —————————————- //
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’):
//
$fruit = $_POST[‘fruit’]; // fruit field
//
if($fruit==’Select One’): // amount selection
$messages .= ‘5. Select A FRUIT<br>’.$lf;
endif;
//
if(strlen($messages)==0): // if all validations are good
$mailheaders = ‘Content-Type: text/plain;’.$lterm; // set extra mail headers
$mailheaders .= ‘X-Mailer: PHP;’.$lterm;
$mailheaders .= ‘X-MSMail-Priority: High;’.$lterm;
$mailheaders .= ‘X-Priority: 1;’.$lterm;
$mailheaders .= ‘Return-path: ‘.$mailfrom.$lterm;
$mailheaders .= ‘Sender: ‘.$mailfrom.$lterm;
$mailheaders .= ‘From: ‘.$mailfrom.$lterm;
if (isset($mailcopy)
&& !empty($mailcopy)):
$mailheaders .= ‘Cc: ‘.$mailcopy.$lterm;
endif;
$mailbody = ” Your selected fruit is {$fruit}
” .$lterm;
ini_set(sendmail_from, $mailfrom);
if (mail($emailadr, $mailsubj, $mailbody, $mailheaders, “-f $mailfrom”)):
ini_restore(sendmail_from);
header(‘Location: http://’.$_SERVER[‘HTTP_HOST’]
.dirname($_SERVER[‘PHP_SELF’])
.’/’.$thankyou)
exit;
endif;
ini_restore(sendmail_from);
$messages = ‘Failed to send email!’;
endif;
// —————————————- //
endif;
//
function set_selected($form_field, $field_value, $field_index)
{
if (isset($_POST[$form_field])
&& !empty($_POST[$form_field])): // if form field is present in post data
if ($field_value == $_POST[$form_field]): // and equals the expected value
$result = ‘selected’; // then this form field should be checked
else: // else
$result = ”; // don’t check it
endif;
else: // when no post data present
if ($field_index == 0): // and this is the first form field in the group
$result = ‘selected’; // then this form field should be checked
else: // else
$result = ”; // don’t check it
endif;
endif;
return $result; // return the selection result
}
?>
in html:
[code=html]
<?php
if(strlen($messages)!=0):
echo ‘<p style=”font-size:11pt;color:red;”>’ .$messages. ‘</p><br>’ .$lf;
endif;
?>
<form name=”myform” action=”<?=basename($_SERVER[‘PHP_SELF’])?>” method=”post”>
<FIELDSET style=”PADDING-RIGHT: 5px; PADDING-LEFT: 5px; PADDING-BOTTOM: 5px; WIDTH: 425px; PADDING-TOP: 5px”><LEGEND><STRONG><FONT color=#003399>SELECT A FRUIT</FONT></STRONG></FONT></LEGEND>
<br>
<select name=”fruit”>
<option <?=set_selected(‘fruit’, ‘Select One’, 0)?>>Select One</option>
<option <?=set_selected(‘fruit’, ‘Apples’, 1)?>>Apples </option>
<option <?=set_selected(‘fruit’, ‘Oranges’, 2)?>>Oranges</option>
<option <?=set_selected(‘fruit’, ‘Grapes’, 3)?>>Grapes</option>
</select><br><br>
</fieldset>
</form>
The method above sends us the email and redirect them to the thank you page. Works great. We need a little bit of change and I don’t know how to do it.
Since the information are already gathered in php using variables, how do we use them on the thank you page? See example below:
[INDENT][INDENT]Your selected fruit is {$fruit} please click on this link (the link will be containing “
Any help is appreciated.
Thank you so much, you guys rock!