PDA

View Full Version : need help with php email form


UD2006
04-10-2008, 11:42 PM
Hi there

I need some help with an email forum, its ready but now I need some help with the php code for sending it to my email. (I temporary removed the emailadres and domain from the php code).

Here is the form code I have at the moment:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
/*<![CDATA[*/
..hide {
display:none;
}

/*]]>*/
</style>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function ShowTR(sel){
var row,table=sel;
while (table.parentNode&&table.nodeName!='TABLE'){
if (!row&&table.nodeName=='TR') row=table;
table=table.parentNode;
}
var rows=table.rows;
for (var zxc0=row.rowIndex+4;zxc0<row.rowIndex+14;zxc0++){
rows[zxc0].style.display=(zxc0-row.rowIndex-4<sel.selectedIndex*2)?'block':'none';
}



}
/*]]>*/
</script>
</head>
<body>
<form action="contact_process.php" method="post" name="inschrijven" id="inschrijven">
<table width="450" border="0">
<tr>
<td><strong> Ik boek voor de volgende reis: </strong></td>
<td><input name="reis" type="text" id="freis" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label>Reisdatum:</label></td>
<td><input name="reisdatum" type="text" id="freisdatum" /></td>
</tr>
<tr>
<td><label>Vertrekdatum:</label></td>
<td><input name="vertrekdatum" type="text" id="freisdatum" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong> Gegevens van de hoofdboeker:</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label>Naam:</label></td>
<td><input name="naam" type="text" id="fnaam" /></td>
</tr>
<tr>
<td><label>Achternaam:</label></td>
<td><input name="achternaam" type="text" id="fachternaam" /></td>
</tr>
<tr>
<td><label>Adres:</label></td>
<td><input name="adres" type="text" id="fadres" /></td>
</tr>
<tr>
<td><label>Postcode:</label></td>
<td><input name="postcode" type="text" id="fpostcode" /></td>
</tr>
<tr>
<td><label>Woonplaats:</label></td>
<td><input name="woonplaats" type="text" id="fwoonplaats" /></td>
</tr>
<tr>
<td><label>Telefoon:</label></td>
<td><input name="telefoon" type="text" id="ftelefoon" /></td>
</tr>
<tr>
<td><label>Email:</label></td>
<td><input name="email" type="text" id="femail" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Hoeveel personen:</strong></td>
<td>&nbsp;</td>
</tr>
<tr>

<td><label>Volwassenen:</label></td>
<td>
<select name="volwassenen" size="1" id="fvolwassenen" onChange="ShowTR(this);">
<option value="nul" selected="selected" >0</option>
<option value="een">1</option>
<option value="twee">2</option>
<option value="drie">3</option>
<option value="vier">4</option>
<option value="vijf">5</option>
</select></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Mede-reizigers per persoon:</strong></td>
<td>&nbsp;</td>
</tr>
<tr class="hide">
<td><label>Naam persoon 1:</label></td>
<td><input name="naam1" type="text" id="fnaam2" /></td>
</tr>
<tr class="hide">
<td><label>Achternaam persoon 1:</label></td>
<td><input name="achternaam1" type="text" id="fachternaam2" /></td>
</tr>
<tr class="hide">
<td><label>Naam persoon 2:</label></td>
<td><input name="naam2" type="text" id="fnaam2" /></td>
</tr>
<tr class="hide">
<td><label>Achternaam persoon 2:</label></td>
<td><input name="achternaam2" type="text" id="fachternaam2" /></td>
</tr>
<tr class="hide">
<td><label>Naam persoon 3:</label></td>
<td><input name="naam3" type="text" id="fnaam2" /></td>
</tr>
<tr class="hide">
<td><label>Achternaam persoon 3:</label></td>
<td><input name="achternaam3" type="text" id="fachternaam2" /></td>
</tr>
<tr class="hide">
<td><label>Naam persoon 4:</label></td>
<td><input name="naam4" type="text" id="fnaam2" /></td>
</tr>
<tr class="hide">
<td><label>Achternaam persoon 4:</label></td>
<td><input name="achternaam4" type="text" id="fachternaam2" /></td>
</tr>
<tr class="hide">
<td><label>Naam persoon 5:</label></td>
<td><input name="naam5" type="text" id="fnaam2" /></td>
</tr>
<tr class="hide">
<td><label>Achternaam persoon 5:</label></td>
<td><input name="achternaam5" type="text" id="fachternaam2" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Indien van toepassing:</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><label>Ik boek deze reis</label></td>
<td><input name="wel" type="radio" value="wel" /> wel
<input name="niet" type="radio" value="niet" />
niet, als priv&eacute;-reis.</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><strong>Overige informatie<br /> en/of dieetwensen:</strong></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><textarea name="overige" cols="35" rows="5" id="foverige"></textarea></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><div align="right">
<input name="Verzenden" type="submit" value="Verzenden" />
</div></td>
<td><input name="Velden legen" type="reset" value="Legen" /></td>
</tr>
</table>
</form>
</body>
</html>


And here is the php code:

<?php

// ------- three variables you MUST change below -------------------------------------------------------
$replyemail="email";//change to your email address
$valid_ref1="http://www.domain";// change "Your--domain" to your domain
$valid_ref2="http://www.domain";// change "Your--domain" to your domain
// -------- No changes required below here -------------------------------------------------------------
// email variable not set - load $valid_ref1 page
if (!isset($_POST['email']))
{
echo "<script language=\"JavaScript\"><!--\n ";
echo "top.location.href = \"$valid_ref1\"; \n// --></script>";
exit;
}

$ref_page=$_SERVER["HTTP_REFERER"];
$valid_referrer=0;
if($ref_page==$valid_ref1) $valid_referrer=1;
elseif($ref_page==$valid_ref2) $valid_referrer=1;
if(!$valid_referrer)
{
echo "<script language=\"JavaScript\"><!--\n alert(\"ERROR - not sent.\\n\\nCheck your 'valid_ref1' and 'valid_ref2' are correct within contact_process.php.\");\n";
echo "top.location.href = \"default.html\"; \n// --></script>";
exit;
}

//check user input for possible header injection attempts!
function is_forbidden($str,$check_all_patterns = true)
{
$patterns[0] = 'content-type:';
$patterns[1] = 'mime-version';
$patterns[2] = 'multipart/mixed';
$patterns[3] = 'Content-Transfer-Encoding';
$patterns[4] = 'to:';
$patterns[5] = 'cc:';
$patterns[6] = 'bcc:';
$forbidden = 0;
for ($i=0; $i<count($patterns); $i++)
{
$forbidden = eregi($patterns[$i], strtolower($str));
if ($forbidden) break;
}
//check for line breaks if checking all patterns
if ($check_all_patterns AND !$forbidden) $forbidden = preg_match("/(%0a|%0d|\\n+|\\r+)/i", $str);
if ($forbidden)
{
echo "<font color=red><center><h3>STOP! Reserveringuv niet verzonden.</font></h3><br><b>
De tekst die u hebt ingevoerd is niet correct.
<br><textarea rows=9 cols=25>";
foreach ($patterns as $key => $value) echo $value."\n";
echo "\\n\n\\r</textarea><br>Klik vorige in uw browser, en bekijk het formulier opnieuw.";
exit();
}
else return $str;
}

$naam = is_forbidden($_POST["naam"]);
$achternaam = is_forbidden($_POST["achternaam"]);
$adres = is_forbidden($_POST["adres"]);
$postcode = is_forbidden($_POST["postcode"]);
$woonplaats = is_forbidden($_POST["woonplaats"]);
$telefoon = is_forbidden($_POST["telefoon"]);
$email = is_forbidden($_POST["email"]);
$naam1 = is_forbidden($_POST["naam1"]);
$achternaam1 = is_forbidden($_POST["achternaam1"]);
$naam2 = is_forbidden($_POST["naam2"]);
$achternaam2 = is_forbidden($_POST["achternaam2"]);
$naam3 = is_forbidden($_POST["naam3"]);
$achternaam3 = is_forbidden($_POST["achternaam3"]);
$naam4 = is_forbidden($_POST["naam4"]);
$achternaam4 = is_forbidden($_POST["achternaam4"]);
$naam5 = is_forbidden($_POST["naam5"]);
$achternaam5 = is_forbidden($_POST["achternaam5"], false);

$success_sent_msg='<p align="center"><strong>&nbsp;</strong></p>
<p align="center"><strong>Uw reserveringuv is succesvol verstuurd,<br>
</strong> we nemen zo spoedig mogelijk contact met u op.</p>
<p align="center">Een copy van uw reservering is naar uw email verzonden.</p>
<p align="center">Bedankt voor uw reservering.</p>';

$replymessage = "Hi $naam

Bedankt voor uw reservering.

We nemen zo spoedig mogelijk contact met u op.

Hier beneden vind u een copy van de reservering:
--------------------------------------------------

Dank u";

$themessage = "naam: $naam";
mail("$replyemail",
"From: $email\nReply-To: $email");
mail("$email",
"Receipt: $thesubject",
"$replymessage",
"From: $replyemail\nReply-To: $replyemail");
echo $success_sent_msg;
?>

The thing is that when I fill in the form and try to send it I get this error message: ERROR - not sent.\\n\\nCheck your 'valid_ref1' and 'valid_ref2' are correct within contact_process.php.

Its not sending anything. Also the dropmenu items need to be send with the code.

Please any help.

Fumigator
04-11-2008, 04:45 PM
The script you are using is depending on a variable called $_SERVER['HTTP_REFERER'], which is described in the manual as such:

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

If the browser you are using doesn't bother to set this, then your script is going to give you the message you are seeing.

One other possibility is the URL you are assigning to $_valid_ref1 is not exactly the same as the value in $_SERVER['HTTP_REFERER']. To find out, simply add this code to the script and see what comes out:


die("<pre>".print_r($_SERVER,TRUE)."</pre>");

UD2006
04-15-2008, 08:58 PM
I have created a simple php process code, to send info from the contact form.
But I got a parse error:

Parse error: syntax error, unexpected '&' in /home/armenier/public_html/process.php on line 2


The code for the form remains the same as above.
In the form are also some radio buttons and drowndown menu, how can I get that info into the process file?

Here is the php process code:

<?php
&to = "skamstra@solcon.nl";
&subject = "Inschrijving";
&reis = &_REQUEST['reis'] ;
&reisdatum = &_REQUEST['reisdatum'] ;
&vertrekdatum = &_REQUEST['vertrekdatum'] ;
&naam = &_REQUEST['naam'] ;
&achternaam = &_REQUEST['achternaam'] ;
&adres = &_REQUEST['adres'] ;
&postcode = &_REQUEST['postcode'] ;
&woonplaats = &_REQUEST['woonplaats'] ;
&telefoon = &_REQUEST['telefoon'] ;
&email = &_REQUEST['email'] ;
&volwassenen = &_REQUEST['volwassenen'] ;
&naam1 = &_REQUEST['naam1'] ;
&achternaam1 = &_REQUEST['achternaam1'] ;
&naam2 = &_REQUEST['naam2'] ;
&achternaam2 = &_REQUEST['achternaam2'] ;
&naam3 = &_REQUEST['naam3'] ;
&achternaam3 = &_REQUEST['achternaam3'] ;
&naam4 = &_REQUEST['naam14'] ;
&achternaam4 = &_REQUEST['achternaam4'] ;
&naam5 = &_REQUEST['naam15'] ;
&achternaam5 = &_REQUEST['achternaam5'] ;
&wel = &_REQUEST['wel'] ;
&niet = &_REQUEST['niet'] ;
&overige = &_REQUEST['overige'] ;
$headers = "From: $email";
$sent = mail($to, $subject, &reis, &reisdatum, &vertrekdatum, &naam, &achternaam, &adres, &postcode, &woonplaats, &telefoon, &email, &volwassenen, &naam1, &achternaam1, &naam2, &achternaam2, &naam3, &achternaam3, &naam4, &achternaam4, &naam5, &achternaam5, &wel, &niet, &overige, $message, $headers) ;
if($sent)
{print "Uw inschrijving is verstuurd."; }
else
{print "Er is een probleem, uw inschrijving is niet verstuurd."; }
?>

Fumigator
04-15-2008, 09:19 PM
You're confusing the $ with the &.