Skip to content

Instantly share code, notes, and snippets.

@marcogrueter
Created August 26, 2012 15:26
Show Gist options
  • Save marcogrueter/3481111 to your computer and use it in GitHub Desktop.
Save marcogrueter/3481111 to your computer and use it in GitHub Desktop.
email template
<?php
// alle variablen durch die CHECK funktion schmeissen
$name = check_input($_POST['name'], "Namen eingeben!");
$email = check_input($_POST['email'], "Email Adresse eingeben!");
$str = check_input($_POST['str'], "Strasse eingeben!");
$plz = check_input($_POST['plz'], "PLZ eingeben!");
$textfeld = check_input($_POST['textfeld'],"Text eingeben!");
//Email validierung
$email = htmlspecialchars($_POST['email']);
if (!preg_match("/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/",$email))
{
die("Keine g&uuml;ltige email adresse!");
}
//PLZ validierung
if (preg_match("/\D/",$plz))
{
die("In der PLZ sind nur Zahlen erlaubt!");
}
if (isset($_POST['anrede']) && ($_POST['anrede'] == "Herr")) {
$anrede = "Herr";
}
else {
$anrede = "Frau";
}
echo $anrede;
//Validation
function check_input($data, $problem =''){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
include '../login/include/connect.inc.php';
//email adresse aus Datenbank holen
$datensatz = mysql_query("SELECT email FROM user WHERE name='admin'");
if (mysql_errno()) die ("MySQL-Error: " . mysql_error());
while($row = mysql_fetch_array($datensatz)) {
$email = $row['email'];
}
$mailAdresse = $email;
$betreff = "Website benachrichtigung";
$nachricht = email_erstellen($textfeld);
/* Mail Verschicken */
mail($mailAdresse, $betreff, $nachricht);
/* Weiterleitung zur Dankes seite */
header('Location: danke.html');
exit();
function email_erstellen($inhalt)
$email = '
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Your Message Subject or Title</title>
<style type="text/css">
#outlook a {padding:0;}
body{width:100% !important; -webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; margin:0; padding:0;}
.ExternalClass {width:100%;}
.ExternalClass, .ExternalClass p, .ExternalClass span, .ExternalClass font, .ExternalClass td, .ExternalClass div {line-height: 100%;}
#backgroundTable {margin:0; padding:0; width:100% !important; line-height: 100% !important;}
img {outline:none; text-decoration:none; -ms-interpolation-mode: bicubic;}
a img {border:none;}
.image_fix {display:block;}
p {margin: 1em 0;}
h1, h2, h3, h4, h5, h6 {color: black !important;}
h1 a, h2 a, h3 a, h4 a, h5 a, h6 a {color: blue !important;}
h1 a:active, h2 a:active, h3 a:active, h4 a:active, h5 a:active, h6 a:active {
color: red !important;
}
h1 a:visited, h2 a:visited, h3 a:visited, h4 a:visited, h5 a:visited, h6 a:visited {
color: purple !important;
}
table td {border-collapse: collapse;}
table { border-collapse:collapse; mso-table-lspace:0pt; mso-table-rspace:0pt; }
a {color: orange;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0" border="0" id="backgroundTable">
<tr>
<td>
' . $inhalt . '
</td>
</tr>
</table>
<!-- End of wrapper table -->
</body>
</html>';
return $email;
}
function show_error($myError)
{
?>
<html>
<body>
<b>Bitte Folgenden Fehler beheben:</b><br />
<?php echo $myError; echo $anrede; ?>
</body>
</html>
<?php
exit();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment