I have written the check_contacts.php and its based on a normal form where the user put in his name, mailaddress which come doown to th mail() function. So normally I use this code:
<?php
$_SESSION["Namn"] = $_POST["Namn"];
$_SESSION["Tel"] = $_POST["Tel"];
$_SESSION["Epost"] = $_POST["Epost"];
$_SESSION["Antal"] = $_POST["Antal"];
//kontaktmail
if ($submit) {
//Checks the name
$errors = array();
$namncheck = trim($_POST["Namn"], " \-"
;
if (!preg_match("/^[a-zA-ZåäöÅÄÖüÜéÉèÈôÔ\-]+[a-zA-ZåäöÅÄÖüÜéÉèÈôÔ\- ]+$/i", $namncheck))
$errors[0] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> ditt namn innehåller ogiltiga tecken eller ev blanksteg, endast A-Ö accepteras';
//Check the phone number
$telcheck = $_POST["Tel"];
if(!preg_match("/^\+46\([1-9][0-9]*\)\d{5,}$|^\+46[1-9]\d{5,}$|^0[1-9]+\d{5,}$|^0[1-9][0-9]*-\d{5,}$/", $telcheck))
$errors[1] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> ditt telnr saknas eller är felaktigt, skriv ex 08-121212, 08121212, +468121212 eller +46(8)121212';
//Check the email
$emailcheck = $_POST["Epost"];
if(!preg_match("/^[a-z0-9\å\ä\ö._-]+@[a-z0-9\å\ä\ö.-]+\.[a-ö]{2,6}$/i", $emailcheck))
$errors[2] = '<span style="float: left"><img src="bilder/warning_obj.gif" alt="Error" title="Error"/></span> din epostadress saknas eller är felaktig';
}
?>
<form action="<?php PHP_SELF ?>" method="post" name="kontakt">
<div align="left">Namn:*</div>
<div align="left"><input type="text" name="Namn" class="<?php if($errors[0]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_name" value="<?php if(count($errors)>0) echo isset($_SESSION["Namn"]) ? $_SESSION["Namn"] : ''; ?>"/>
<?php if(!$errors[0] && !$submit){
echo '<script type="text/javascript">
document.getElementById("theField_name"
.focus();
</script>
<noscript> </noscript>';
}
?>
<?php if($errors[0]){
echo '<script type="text/javascript">
document.getElementById("theField_name"
.select();
</script><noscript> </noscript>';
}
?>
</div>
<div align="left">Tel:*</div>
<div align="left"><input name="Tel" type="text" class="<?php if($errors[1]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_tel" value="<?php if(count($errors)>0) echo isset($_SESSION["Tel"]) ? $_SESSION["Tel"] : ''; ?>"/>
<?php if($errors[1]){
echo '<script type="text/javascript">
document.getElementById("theField_tel"
.select();
</script><noscript> </noscript>';
}
?>
</div>
<div align="left">Epost:*</div>
<div align="left"><input type="text" name="Epost" class="<?php if($errors[2]){ echo "bakgrund_error"; } else { echo "bakgrund"; } ?>" id="theField_epost" value="<?php if(count($errors)>0) echo isset($_SESSION["Epost"]) ? $_SESSION["Epost"] : ''; ?>"/>
<?php if($errors[2]){
echo '<script type="text/javascript">
document.getElementById("theField_epost"
.select();
</script><noscript> </noscript>';
}
?>
</div>
<div align="left">Antal personer:</div>
<div align="left"><input type="text" name="Antal" class="bakgrund" value="<?php if(count($errors)>0) echo isset($_SESSION["Antal"]) ? $_SESSION["Antal"] : ''; ?>" onkeyup="if(!this.value.match(/^\d+$/)){ this.value=(this.value.match(/\d+/))?this.value.match(/\d+/):''; }"/></div>
<br/>
<div align="left">Önskar offert/information på följande utbildningsavsnitt:</div>
<div align="left"><input type="checkbox" name="grund_hlr" value="Grund-HLR" class="bakgrund"/>Grund-HLR<br/>
<input type="checkbox" name="d_hlr" value="D-HLR" class="bakgrund"/>D-HLR<br/>
<input type="checkbox" name="s_hlr" value="S-HLR" class="bakgrund"/>S-HLR<br/>
<!--<input type="checkbox" name="a_hlr" value="A-HLR" class="bakgrund"/>A-HLR<br/> OM denna läggs till glöm inte att lägg in denna i mail()!-->
<input type="checkbox" name="barn_hlr" value="Barn-HLR" class="bakgrund"/>Barn-HLR</div>
<br/>
*=Obligatorisk uppgift!<br/>
<br/>
<?php if($submit){
if($errors[0]){
echo '<script type="text/javascript">
document.getElementById("theField_name"
.focus();
document.getElementById("theField_name"
.select();
</script><noscript> </noscript>';
}
elseif($errors[1]){
echo '<script type="text/javascript">
document.getElementById("theField_tel"
.focus();
document.getElementById("theField_tel"
.select();
</script><noscript> </noscript>';
}
elseif($errors[2]){
echo '<script type="text/javascript">
document.getElementById("theField_epost"
.focus();
document.getElementById("theField_epost"
.select();
</script><noscript> </noscript>';
}
}
?>
<input name="submit" type="submit" value="Skicka" class="bakgrund"/><br/>
<br/>
</form>
<?php
if($submit){
// If something goes wrong show this msg
if (count($errors)>0) {
echo "<b>OBS! Obligatorisk information saknas:</b><br/>";
echo "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"75%\" summary=\"Felkontroll\">";
echo "<tr><td align=\"left\">";
foreach($errors as $fel)
echo "$fel<br/>";
echo "</td></tr>";
echo "</table>";
echo "<br />Ange den information som saknas och skicka formuläret igen. Tack! <br />";
} else {
mail("inger@test.se","Kontakt önskas","Kontakta: $Namn på $Tel för följande kurs:\r$grund_hlr\r$d_hlr\r$s_hlr\r$barn_hlr\r\rAntal personer: $Antal","From:$Namn<$Epost>"
;
mail("ingerm.olson@test.com","Kontakt önskas","Kontakta: $Namn på $Tel för följande kurs:\r$grund_hlr\r$d_hlr\r$s_hlr\r$barn_hlr\r\rAntal personer: $Antal","From:$Namn<$Epost>"
;
echo "<b>OBS!</b> Meddelandet skickat och vi kommer kontakta er inom kort!";
session_unset();
session_destroy();
}
}
?>
The production site is placed on a linux server so therefore I don't have any problem with From: $Namn<$Epost>. I don't have any mailserver so I'm using a third parties server here. Some of the text is in swedish but I think you should understand the majority of it.
Edited 1 time(s). Last edit at 03/08/2008 01:56AM by psn.