PHP
Verfasst: Mi 19. Aug 2015, 15:48
Kennt sich wer mit PHP aus und möchte mir bei was helfen ?
Code: Alles auswählen
<?php
error_reporting(1);
$sicherheitsabfrage = true; //true oder false (ein- oder ausblenden)
$error = false;
$errors = array();
$errormessage = "";
$receiver = isset($_POST["e_m_a_i_l"]) ? $_POST["e_m_a_i_l"] : 'EMAIL';
$chkSendCopy = isset($_POST["chkSendCopy"]) ? true : false;
$mysendermail = "bla@hec.wtf";
$sendermail = "bla@hec.wtf";
$subject = "Anmeldung";
srand((double)microtime()*1000000);
$zahl1 = rand(0, 10);
$zahl2 = rand(0, 10);
$ergebnis = $zahl1 + $zahl2;
function check_email ($string) {
return preg_match('/^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/i', $string);
}
function check_onlynumbers ($string) {
return preg_match('/^[0-9,.]{1,}$/', $string);
}
function check_onlyletters ($string) {
return preg_match('/^[a-zA-ZäöüÄÖÜß]{1,}$/', $string);
}
function send_email ($subject, $body, $receiver, $html = 1, $sendermail,$mysendermail) {
if ($html != 1) {
$body = str_replace('<br />', "\n", $body);
$body = str_replace('<br>', "\n", $body);
$body = strip_tags($body);
}
$subject = str_replace('\n', '', $subject);
$subject = str_replace('\r', '', $subject);
$header = 'MIME-Version: 1.0' . "\n";
$header .= $html ? 'Content-type: text/html; charset=iso-8859-15'."\n" : "";
$header .= 'From: '.$receiver.' <'.$receiver.'>'."\n";
// $header .= 'From: '.$_SERVER["SERVER_ADMIN"]."\n";
if($sendermail != "") {
$header .= 'From: '.$mysendermail."\n";
//$header .= 'Reply-To: '.$sendermail."\n";
} else {
$header .= 'From: '.$_SERVER["SERVER_ADMIN"]."\n";
}
if (mail($receiver, $subject, $body, $header)) {
return true;
} else {
return false;
}
}
function array_stripslashes(&$var) {
if(is_string($var)) {
$var = stripslashes($var);
} else {
if(is_array($var))
foreach($var as $key => $value)
array_stripslashes($var[$key]);
}
}
if(get_magic_quotes_gpc()){
array_stripslashes($_GET);
array_stripslashes($_POST);
array_stripslashes($_REQUEST);
array_stripslashes($_COOKIE);
}
if (!empty($_POST)) {
// Prüfung für das Feld "Nickname"
$errors["Nickname"] = null;
if (empty($_POST["Nickname"])) {
$error = true;
$errors["Nickname"] = ' class="error"';
$errormessage .= 'Feld "Nickname" muss ausgefüllt werden.<br>';
}
// Prüfung für das Feld "Geburtjahr:"
$errors["Geburtjahr"] = null;
if (empty($_POST["Geburtjahr"])) {
$error = true;
$errors["Geburtjahr"] = ' class="error"';
$errormessage .= 'Feld "Geburtjahr:" muss ausgefüllt werden.<br>';
}
if (!check_onlynumbers($_POST["Geburtjahr"])) {
$error = true;
$errors["Geburtjahr"] = ' class="error"';
$errormessage .= empty($_POST["Geburtjahr"]) ? '' : 'In das Feld "Geburtsjahr:" kannst Du nur Zahlen eingeben<br>';
}
// Prüfung für das Feld "E-Mail:"
$errors["Email"] = null;
if (empty($_POST["Email"])) {
$error = true;
$errors["Email"] = ' class="error"';
$errormessage .= 'Feld "E-Mail:" muss ausgefüllt werden.<br>';
}
if (!check_email($_POST["Email"])) {
$error = true;
$errors["Email"] = ' class="error"';
$errormessage .= empty($_POST["Email"]) ? '' : 'E-Mail-Adresse ist ungültig<br>';
} else {
//$sendermail = $_POST["Email"];
$sendermail = "join@hec.wtf";
}
// Prüfung für das Feld "Bist Du auch außerhalb vom regulären Spielbetrieb bereit, Dich an Trainings zu beteiligen und Dich weiterzubilden?"
$errors["Bereit"] = null;
if (empty($_POST["Bereit"])) {
$error = true;
$errors["Bereit"] = ' class="error"';
$errormessage .= 'Feld "Einen oder mehrere Gründe, warum du hier mitspielen möchtest:" muss ausgefüllt werden.<br>';
}
if($sicherheitsabfrage === true) {
if(empty($_POST["ergebnis"])) {
$error = true;
$errors["ergebnis"] = ' class="error"';
$errormessage .= 'Das Ergebnis der Rechenaufgabe muss angegeben werden.<br>';
} elseif($_POST["ergebnis"] != $_POST["tmpErgebnis"]) {
$error = true;
$errors["ergebnis"] = ' class="error"';
$errormessage .= 'Das Ergebnis der Rechenaufgabe ist falsch.<br>';
}
}
}
$_text_Nickname = (!empty($_POST["Nickname"]) ? htmlspecialchars($_POST["Nickname"], ENT_QUOTES, "iso-8859-15") : null);
$_text_Geburtjahr = (!empty($_POST["Geburtjahr"]) ? htmlspecialchars($_POST["Geburtjahr"], ENT_QUOTES, "iso-8859-15") : null);
$_text_Email = (!empty($_POST["Email"]) ? htmlspecialchars($_POST["Email"], ENT_QUOTES, "iso-8859-15") : null);
$_radio_Bereit_Ja = (!empty($_POST["Bereit"]) && $_POST["Bereit"] == "Ja" ? ' checked="checked"' : null);
$_radio_Bereit_Nein = (!empty($_POST["Bereit"]) && $_POST["Bereit"] == "Nein" ? ' checked="checked"' : null);
$_textarea_Visitenkarte = (!empty($_POST["Visitenkarte"]) ? htmlspecialchars($_POST["Visitenkarte"], ENT_QUOTES, "iso-8859-15") : null);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15" />
<title>Ich will dabei sein!</title>
<style type="text/css">
body {
font: 12px Verdana, Tahoma, Arial, Helvetica, sans-serif;
color: #333333;
}
legend {
font: 14px Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #333333;
}
.formtitle {
font: 14px Verdana, Tahoma, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #333333;
}
h1, p {
margin: 10px; padding: 0px;
}
textarea {
width: 350px;
padding: 2px;
font: normal 12px Verdana, sans-serif;
border: 1px solid #828790;
height: 100px;
color: #333;
}
input.button {
margin: 0;
font: bolder 12px Arial, Sans-serif;
border: 1px solid #828790;
padding: 1px;
background: #FFF;
color: #CC0000;
}
.error_msg {
padding: 4px;
background-color: #ffeeee;
border: 1px dotted #cc0000;
margin: 5px 10px 5px 10px;
color: #cc0000;
}
.error { color: #cc0000; }
fieldset {
width: 0px;
border: 0px none;
padding: 10px;
}
/*div.formgenerator label,*/
div.formgenerator .controlset span {
width: 150px;
display: block;
float: left;
text-align: right;
}
div.formgenerator label { margin: 5px; }
div.formgenerator .controlset span { margin: 0px 0px 0px 5px; }
div.formgenerator .controlset label {
display: inline;
float: none;
}
div.formgenerator .controlset input { margin: 0px 0px 0px 10px; }
div.formgenerator input,
div.formgenerator select,
div.formgenerator textarea {
margin: 2px 2px 2px 5px;
}
</style>
</head>
<body bgcolor="#F1F1F1">
<legend><span class="formtitle">Ich will dabei sein!</span></legend>
<?php
if ($error || empty($_POST)) {?>
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'iso-8859-15'); ?>" method="post">
<input type="hidden" name="tmpErgebnis" value="<?php echo $ergebnis ?>" />
<div class="formgenerator">
<p style="width: 380px;">Mittels untenstehendem Formular kannst du dich bei uns bewerben:</p>
<?php
if ($error) {
?>
<div class="error_msg">Mit * bezeichnete Felder sind zwingend auszufüllen.<p><?php echo $errormessage ?></p></div>
<?php
}
?>
<table cellspacing="2" width="380" >
<tr>
<td><label for="Nickname" style="color: #000000; font-weight: bold;"<?php echo (!empty($errors["Nickname"]) ? $errors["Nickname"] : null); ?>>Nickname: *</label></td>
<td><input type="text" maxlength="150" id="Nickname" name="Nickname" value="<?php echo $_text_Nickname; ?>" style="width: 200px;" /></td>
</tr>
<tr>
<td><label for="Geburtjahr" style="color: #000000; font-weight: bold;"<?php echo (!empty($errors["Geburtjahr"]) ? $errors["Geburtjahr"] : null); ?>>Geburtsjahr: *</label></td>
<td><input type="text" maxlength="4" id="Geburtjahr" name="Geburtjahr" value="<?php echo $_text_Geburtjahr; ?>" style="width: 200px;" /></td>
</tr>
<tr>
<td><label for="Email" style="color: #000000; font-weight: bold;"<?php echo (!empty($errors["Email"]) ? $errors["Email"] : null); ?>>E-Mail: *</label></td>
<td><input type="text" id="Email" name="Email" value="<?php echo $_text_Email; ?>" style="width: 200px;" /></td>
</tr>
<table cellspacing="2" width="380" >
<tr>
<td valign="top"><span style="color: #000000; font-weight: bold;"<?php echo (!empty($errors["Bereit"]) ? $errors["Bereit"] : null); ?>>Bist Du auch außerhalb vom regulären Spielbetrieb bereit, Dich weiterzubilden? *</span></td>
</tr>
<tr>
<td><input type="radio" id="Ja" name="Bereit" value="Ja"<?php echo $_radio_Bereit_Ja; ?> /><label for="Ja">Ja</label><br />
<input type="radio" id="Nein" name="Bereit" value="Nein"<?php echo $_radio_Bereit_Nein; ?> /><label for="Nein">Nein</label><br />
</td>
</tr>
<table cellspacing="2" width="380" >
<tr>
<td valign="top"><label for="Visitenkarte" style="color: #000000; font-weight: bold;"<?php echo (!empty($errors["Visitenkarte"]) ? $errors["Visitenkarte"] : null);?>>Einen oder mehrere Gründe, warum du hier mitspielen möchtest:</label></td>
</tr>
<tr>
<td><textarea id="Visitenkarte" name="Visitenkarte" rows="4" cols="50" style="width: 400px; height: 50px;"><?php echo $_textarea_Visitenkarte; ?></textarea></td>
</tr>
<table cellspacing="2" width="380" >
<tr>
<td><label for="chkSendCopy" style="color: #000000; font-weight: bold;">Eine Kopie an mich senden</label></td>
<td><input type="checkbox" id="chkSendCopy" name="chkSendCopy" <?php echo (isset($_POST["chkSendCopy"]) ? 'checked="checked"' : '') ?> /></td>
</tr>
<?php
if($sicherheitsabfrage === true) {
?>
<tr>
<td colspan="2" style="border-bottom: 0px none;"><br />Bitte löse die folgende Rechenaufgabe zur Verhinderung von Spam. Danke.</td>
</tr>
<tr>
<td align="right" style="border-top: 0px none;"><label for="ergebnis"<?php echo (!empty($errors["ergebnis"]) ? $errors["ergebnis"] : null); ?>><b><?php echo $zahl1.' + '.$zahl2.' =' ?></b></label></td>
<td style="border-top: 0px none;"><input type="text" name="ergebnis" value="" size="3" /> *</td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td><input type="submit" value="Absenden" /></td>
</tr>
</table>
</div>
</form>
<?php
} else {
$body = "<table cellspacing=\"5\">";
$body .= "<tr><td>Nickname:</td><td>".htmlspecialchars(!empty($_POST["Nickname"]) ? $_POST["Nickname"] : "", ENT_QUOTES, "iso-8859-15")."</td></tr>";
$body .= "<tr><td>Geburtjahr::</td><td>".htmlspecialchars(!empty($_POST["Geburtjahr"]) ? $_POST["Geburtjahr"] : "", ENT_QUOTES, "iso-8859-15")."</td></tr>";
$body .= "<tr><td>E-Mail::</td><td>".htmlspecialchars(!empty($_POST["Email"]) ? $_POST["Email"] : "", ENT_QUOTES, "iso-8859-15")."</td></tr>";
$body .= "<tr><td>Bist Du auch außerhalb vom regulären Spielbetrieb bereit, Dich an Trainings zu beteiligen und Dich weiterzubilden?:</td><td>".htmlspecialchars(!empty($_POST["Bereit"]) ? $_POST["Bereit"] : "", ENT_QUOTES, "iso-8859-15")."</td></tr>";
$body .= "<tr><td valign=\"top\">";
$body .= "Was wir sonst noch über dich wissen sollten? Dies hier ist Deine Visitenkarte, mit der Du dich bei uns bewirbst. Schreibe möglichst ausführlich etwas über Dich, damit wir Dich im Vorfeld besser kennen lernen können!:</td><td>".nl2br(htmlspecialchars(!empty($_POST["Visitenkarte"]) ? $_POST["Visitenkarte"] : "", ENT_QUOTES, "iso-8859-15"))."</td></tr>";
$body .= "<tr><td colspan=\"2\"></td></tr></table>";
if(send_email('Ich will dabei sein!', $subject, $body, $receiver, $html = 1, $sendermail,$mysendermail)) {
?>
<p>Vielen Dank für Deine Anmeldung.</p>
<?php
if($chkSendCopy) {
send_email('Kopie: Ich will dabei sein!', $body, $sendermail, 1, $mysendermail);
}
} else {
?>
<p>Das Formular konnte leider nicht abgesendet werden. Bitte versuchen Sie es später noch einmal.</p>
<?php
}
}
?>
</body>
</html>
Code: Alles auswählen
<?php
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$from = "bla@hec.wtf";
$to = "bla@hec.wtf";
$subject = "PHP Mail Test script";
$message = "This is a test to check the PHP Mail functionality";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
echo "Test email sent";
?>
Code: Alles auswählen
function send_email ($subject, $body, $receiver, $html = 1, $sendermail,$mysendermail)
Code: Alles auswählen
send_email('Ich will dabei sein!', $subject, $body, $receiver, $html = 1, $sendermail,$mysendermail)
Code: Alles auswählen
send_email('Ich will dabei sein!' . $subject, $body, $receiver, $html = 1, $sendermail,$mysendermail)