Last active
December 11, 2015 02:39
-
-
Save droid242/4532231 to your computer and use it in GitHub Desktop.
Simple mail script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(isset($_POST['email'])) { | |
// EDIT THE 2 LINES BELOW AS REQUIRED | |
$email_to = "[email protected]"; | |
$email_subject = "Webes megkeresés"; | |
$thx = "thx.html"; | |
function died($error) { | |
// your error code can go here | |
echo "Sajnálom, de valami probléma van az elküldendő űrlappal. "; | |
echo "A következő hibák jelentkeztek:<br /><br />"; | |
echo $error."<br /><br />"; | |
echo "Kérem lépjen vissza és javítsa a hibát.<br /><br />"; | |
die(); | |
} | |
// validation expected data exists | |
if(!isset($_POST['first_name']) || | |
!isset($_POST['email']) || | |
!isset($_POST['telephone']) || | |
!isset($_POST['comments'])) { | |
died('Sajnálom, de valami probléma van az elküldendő űrlappal.'); | |
} | |
$first_name = $_POST['first_name']; // required | |
$email_from = $_POST['email']; // required | |
$telephone = $_POST['telephone']; // not required | |
$comments = $_POST['comments']; // required | |
$error_message = ""; | |
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; | |
if(!preg_match($email_exp,$email_from)) { | |
$error_message .= 'Érvénytelen, vagy hiányzó e-mail cím.<br />'; | |
} | |
$string_exp = "/^[A-Za-z .'-öÖüÜóÓőŐúÚéÉáÁűŰíÍ]+$/"; | |
if(!preg_match($string_exp,$first_name)) { | |
$error_message .= 'Érvénytelen, vagy hiányzó vezetéknév.<br />'; | |
} | |
if(strlen($comments) < 2) { | |
$error_message .= 'Érvénytelen, vagy hiányzó üzenet!<br />'; | |
} | |
if(strlen($error_message) > 0) { | |
died($error_message); | |
} | |
$email_message = "Megkeresés honlapon keresztül:<br /><br />"; | |
function clean_string($string) { | |
$bad = array("content-type","bcc:","to:","cc:","href"); | |
return str_replace($bad,"",$string); | |
} | |
$email_message .= "Vezetéknév: ".clean_string($first_name)."<br />"; | |
$email_message .= "E-mail: ".clean_string($email_from)."<br />"; | |
$email_message .= "Telefonszám: ".clean_string($telephone)."<br />"; | |
$email_message .= "Üzenet:<br />".clean_string($comments)."<br />"; | |
// create email headers | |
$headers = "From: ".$email_from."\r\n"; | |
$headers .= "Reply-To: ".$email_from."\r\n"; | |
$headers .= "X-Mailer: PHP/".phpversion()."\r\n"; | |
$headers .= "MIME-Version: 1.0 \r\n"; | |
$headers .= "Content-Type: text/html; charset=UTF-8 \r\n"; | |
@mail($email_to, $email_subject, $email_message, $headers); | |
header("Location: $thx"); | |
?> | |
<!-- p>Köszönöm, hogy megkeresett! <br />Hamarosan üzenek Önnek!</p> | |
<p><a href="javascript:history.back()">Vissza</a></p --> | |
<script>location.replace('<?php echo $thx;?>')</script> | |
<?php | |
} | |
die(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minek a die() a végére? Illetve ha a file legvége PHP kód, akkor a ?> is elhagyható.