Why do I lose variables in this script?
Posted: Sat Jul 31, 2004 1:45 pm
I open this script in a target=_blank page, and pass contact_email, listing_no, and company_name to it in the url. The variables seem to be outputted in html with no problems, but they are lost when "submit" is clicked.
What am I doing wrong here?
What am I doing wrong here?
Code: Select all
<?php
if ($mode == "submit") {
$headers .= "MIME-Version: 1.0 \n";
$headers .= "Content-type: text/html; charset=iso-8859-1 \n";
$headers .= "from:$mail_from\r\n$email_from";
$mail_subject .= "In regard to your ad: $listing_no";
if (@mail ($contact_email, $mail_subject, $mail_body, $headers)) {
print ("The e-mail was sent successfully");
// debugging -- $contact_email is null!
print $contact_email." ".$mail_subject." ".$mail_body." ".$headers;
} else {
print ("an error occurred while sending the e-mail");
}
exit;
}
?>
<html>
<head>
<title>Send message</title>
<script language="javascript">
function DoSubmit ()
{
if (document.form.mail_from.value == "") {
alert ("Please enter your e-mail address in 'from' field");
document.form.mail_from.focus ();
return "";
}
if (document.form.mail_body.value == "") {
alert ("Please enter a message in 'body' field");
document.form.mail_body.focus ();
return "";
}
document.form.submit ();
}
</script>
</head>
<body>
<!--
html starts here
-->
<form action="<?php print ($PHP_SELF); ?>" method="post" name="form">
<table>
<tr>
<td>From:</td>
<td><input type="text" name="mail_from" size="40"></td>
</tr>
<tr>
<td>To: </td>
<td><? echo $company_name.", ".$contact_email; ?></td>
</tr>
<tr>
<td>Subject: </td>
<td><? echo "In regard to your ad: ".$listing_no; ?></td>
</tr>
<tr>
<td valign="top">Body:</td>
<td><textarea name="mail_body" cols="40" rows="10"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="mode" value="submit"></td>
<td><input type="button" onclick="DoSubmit ()" value="Send e-mail"></td>
</tr>
</table>
</form>
</body>
</html>
?>