S
sevY
Hi,
da ja einige Fragen aufgetreten sind, habe ich anbei mal ein Script, welches ein PHP Emailformular darstellt.
Die Eingaben des Formulars werden mittels Javascript überprüft. Dabei ist eine kleine „JavaScript Detection“ eingebaut, die es erlaubt, bei fehlendem JavaScript den Button zum Versenden des Formulars „auszublenden“.
Wird die Email erfolgreich abgeschickt, bekommt der User eine Mitteilung, in dem sich eine JavaScript alert() Box öffnet und ihm dieses mitgeteilt wird. Diese Methode wird auch für die Fehlerbenachrichtigung verwendet.
Pflichtfelder sind hier NAME und (TELEFON oder EMAIL).
Die Email wird dazu noch auf Integrität gecheckt.
Gruß
Yves
da ja einige Fragen aufgetreten sind, habe ich anbei mal ein Script, welches ein PHP Emailformular darstellt.
Die Eingaben des Formulars werden mittels Javascript überprüft. Dabei ist eine kleine „JavaScript Detection“ eingebaut, die es erlaubt, bei fehlendem JavaScript den Button zum Versenden des Formulars „auszublenden“.
Wird die Email erfolgreich abgeschickt, bekommt der User eine Mitteilung, in dem sich eine JavaScript alert() Box öffnet und ihm dieses mitgeteilt wird. Diese Methode wird auch für die Fehlerbenachrichtigung verwendet.
Pflichtfelder sind hier NAME und (TELEFON oder EMAIL).
Die Email wird dazu noch auf Integrität gecheckt.
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
.singleline
{
width:176px;
height:12px;
margin:0px 0px 5px 0px;
padding:2px 2px 2px 2px;
border-width:1px;
border-color:#949fae;
border-style:solid;
background-color:#ffffff;
color:#617188;
font-family:Verdana,Helvetica,Arial,sans-serif;
font-size:10px;
line-height:12px;
font-weight:normal;
text-decoration:none;
}
.multiline
{
width:362px;
height:80px;
margin:0px 0px 8px 0px;
padding:2px 2px 2px 2px;
border-width:1px;
border-color:#949fae;
border-style:solid;
background-color:#ffffff;
color:#617188;
font-family:Verdana,Helvetica,Arial,sans-serif;
font-size:10px;
line-height:12px;
font-weight:normal;
text-decoration:none;
overflow:hidden;
}
.submit
{
width:100px;
margin:5px 0px 0px 0px;
padding:0;
border-width:1px;
border-color:#949fae;
border-style:solid;
background-color:#ffffff;
color:#617188;
font-family:Verdana,Helvetica,Arial,sans-serif;
font-size:9px;
line-height:12px;
font-weight:bold;
text-decoration:none;
}
</style>
<script language="javascript" type="text/javascript">
function integrityCheck(x)
{
var a=false;
var res=false;
if(typeof(RegExp)=='function')
{
var b=new RegExp('abc');
if(b.test('abc')==true)
{
a=true;
}
}
if(a==true)
{
reg=new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+
'(\\@)([a-zA-Z0-9\\-\\.]+)'+
'(\\.)([a-zA-Z]{2,4})$');
res=(reg.test(x));
}
else
{
res=(x.search('@') >= 1 && x.lastIndexOf('.') > x.search('@') && x.lastIndexOf('.') >= x.length-5)
}
return(res);
}
function checkForm(name,phone,mail)
{
if(document.contact.name.value=='' || document.contact.name.value=='Name*')
{
alert('Bitte geben Sie einen Namen ein!');
document.contact.name.focus();
return false;
break;
}
else if((document.contact.phone.value=='' || document.contact.phone.value=='Telefon*') && integrityCheck(document.contact.mail.value)==false)
{
alert('Bitte geben Sie eine Telefonnummer oder eine Emailadresse ein!');
document.contact.phone.focus();
return false;
break;
}
else
{
document.contact.submit();
return true;
break;
}
}
</script>
<title>Form</title>
</head>
<?php
$recipient='yves@das-studio.com';
if(isset($_POST['target']))
{
$boundary=strtoupper(md5(uniqid(time())));
$header="From:".$_POST['name']."<".$_POST['mail'].">\n";
$header.="Reply-To: ".$_POST['mail']."\n";
$header.="X-Mailer: PHP/" .phpversion(). "\n";
$header.="X-Sender-IP: ".$_SERVER["REMOTE_ADDR"]."\n";
$content=
$_POST['message'].'
Name: '.$_POST['name'].'
Telefon: '.$_POST['phone'].'
Browser: '.$_SERVER['HTTP_USER_AGENT'].'
Gateway: '.getHostByAddr($_SERVER['REMOTE_ADDR']).'
IP: '.$_SERVER['REMOTE_ADDR'];
if(mail($recipient,$_POST['subject'].', Anfrage vom '.date('d.m.Y'),$content,$header))
{
$notify='onload="javascript:alert(\'Vielen Dank, '.$_POST['name'].'. Ihre Email wurde zugestellt.\');"';
}
}
echo'<body'.(isset($notify) ? ' '.$notify.'>' : '>');
?>
<form name="contact" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="target" value="0" />
<input class="singleline" type="text" name="name" value="Name*" />
<input class="singleline" type="text" name="phone" value="Telefon*" /><br />
<input class="singleline" type="text" name="mail" value="Email*" />
<input class="singleline" type="text" name="subject" value="Betreff" /><br />
<textarea class="multiline" name="message">Nachricht</textarea><br />
<script language="javascript" type="text/javascript">
var submit='<input class="submit" type="button" value="Email" onclick="javascript:checkForm(document.contact.name.value,document.contact.phone.value,document.contact.mail.value);">';
document.write(submit);
</script>
<noscript>
<img src="img/enable_javascript.gif" alt="Enable JavaScript" />
</noscript>
</form>
</body>
</html>
Gruß
Yves