私はPHPには新しく、私は電子メールを送るためにホームページに投稿付きのシンプルなフォームを使用しています。PHPメール()が完全にチェックされていますが、私は空メールを受け取ります
これは形式です:私見空のメールが私に介して取得しないはずです、私は得ることに保つものの
<?php
$to = "[email protected]";
$subject = $_POST["radio"];
$email = $_POST["email"];
$returnPage = 'http://myhomepage.de#success';
$returnErrorPage = 'http://myhomepage.de#error';
$dodgy_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"bcc:"
);
function is_valid_email($email) {
return preg_match('#^[a-z0-9.!\#$%&\'*+-/=?^_`{|}~][email protected]([0-9.]+|([^\s]+\.+
[a-z]{2,6}))$#si', $email);
}
function contains_bad_str($str_to_test) {
$bad_strings = array(
"content-type:"
,"mime-version:"
,"multipart/mixed"
,"Content-Transfer-Encoding:"
,"bcc:"
,"cc:"
,"to:"
);
foreach($bad_strings as $bad_string) {
if(eregi($bad_string, strtolower($str_to_test))) {
header("Location: " . $returnErrorPage);
exit;
}
}
}
function contains_newlines($str_to_test) {
if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) {
header("Location: " . $returnErrorPage);
exit;
}
}
function isEmpty($str_to_test){
return preg_match('/\S/', $str_to_test);
}
function checkFormCompletion($str_to_test){
contains_bad_str($str_to_test);
if(isEmpty($str_totest)){
header("Location: " . $returnErrorPage);
exit;
}
else
return $str_to_test;
}
if($_SERVER['REQUEST_METHOD'] != "POST"){
header("Location: " . $returnErrorPage);
exit;
}
if (!is_valid_email($email)) {
header("Location: " . $returnErrorPage);
exit;
}
$body .= "Firma: " .checkFormCompletion($_POST['firm']);
$body .= "\n";
$body .= "Ansprechpartner: " .checkFormCompletion($_POST['salutation']) ." "
.checkFormCompletion($_POST['name']);
$body .= "\n";
$body .= "Adresse: " .checkFormCompletion($_POST['address']);
$body .= "\n";
$body .= "Telefonnummer: " .checkFormCompletion($_POST['phoneno']);
$body .= "\n";
$body .= "\n";
$body .= "Anfrage: " .checkFormCompletion($_POST['text']);
contains_bad_str($email);
contains_bad_str($subject);
contains_newlines($email);
contains_newlines($subject);
checkFormCompletion($subject);
if(isset($_POST['url']) && $_POST['url'] == ''){
$mailSent = @mail($to, $subject, $body, "From: ".$email);
}
else {
header("Location: " . $returnErrorPage);
}
if($mailSent == TRUE) {
header("Location: " . $returnPage);
} else {
header("Location: " . $returnErrorPage);
}
exit();
?>
:
<form data-abide action="anfrage.php" method="post">
\t <fieldset>
\t \t <div class="row">
\t \t \t <div class="large-12 columns">
\t \t \t \t <label>Firma
\t \t \t \t \t <input type="text" name="firm" placeholder="Firma" />
\t \t \t \t </label>
\t \t \t </div>
\t \t </div>
\t \t <div class="row">
\t \t \t \t <div class="large-4 columns">
\t \t \t \t \t <label>Anrede
\t \t \t \t \t \t <select name="salutation">
\t \t \t \t \t \t \t <option value="-">-</option>
\t \t \t \t \t \t \t <option value="Herr">Herr</option>
\t \t \t \t \t \t \t <option value="Frau">Frau</option>
\t \t \t \t \t \t </select>
\t \t \t \t \t </label>
\t \t \t \t </div>
\t \t \t <div class="large-8 columns">
\t \t \t \t <label>Name <small>benötigt</small>
\t \t \t \t \t <input type="text" name="name" placeholder="Ansprechpartner" required pattern="[a-zA-Z]+">
\t \t \t \t </label>
\t \t \t \t <small class="error">Bitte geben Sie einen Ansprechpartner an!</small>
\t \t \t </div>
\t \t </div>
\t \t <div class="row">
\t \t \t <div class="large-4 columns">
\t \t \t \t <label>Adresse <small>benötigt</small>
\t \t \t \t \t <input type="text" name="address" placeholder="Strasse, PLZ, Stadt" />
\t \t \t \t </label>
\t \t \t \t <small class="error">Bitte geben Sie eine Adresse an!</small>
\t \t \t </div>
\t \t \t <div class="large-4 columns">
\t \t \t \t <label>eMail <small>benötigt</small>
\t \t \t \t \t <input type="eMail" name="email" placeholder="eMail" required/>
\t \t \t \t </label>
\t \t \t \t <small class="error">Bitte geben Sie eine gültige eMail-Adresse an!</small>
\t \t \t </div>
\t \t \t <div class="large-4 columns">
\t \t \t \t <label>Telefon <small>benötigt</small>
\t \t \t \t \t <input type="text" name="phoneno" placeholder="..." required/>
\t \t \t \t </label>
\t \t \t \t <small class="error">Bitte geben Sie eine gültige Telefonnummer an!</small>
\t \t \t </div>
\t \t </div>
\t \t <div class="row">
\t \t \t <div class="large-6 columns">
\t \t \t \t <label>Art der Anfrage</label>
\t \t \t \t <input type="radio" name="radio" id="dryhire" value="Vermietung"><label for="dryhire">Vermietung</label>
\t \t \t \t <input type="radio" name="radio" id="event" value="Veranstaltung"><label for="event">Veranstaltung</label>
\t \t \t \t <input type="radio" name="radio" id="consultation" value ="Beratung"><label for="consultation">Beratung</label>
\t \t \t </div>
\t \t </div>
\t \t <div class="row">
\t \t \t <div class="large-12 columns">
\t \t \t \t <label>Was können wir für Sie tun?<small>benötigt</small>
\t \t \t \t \t <textarea name="text" placeholder="Erläutern Sie uns kurz was Sie wann und wo benötigen." required pattern=""></textarea>
\t \t \t \t </label>
\t \t \t \t <small class="error">Bitte erläutern Sie kurz Ihr Anliegen!</small>
\t \t \t </div>
\t \t </div>
\t \t <div class="antispam">Wenn Sie kein Roboter sind lassen sie diesen Bereich einfach leer: <input type="text" name="url" /></div>
\t \t <button class="large-12 columns button" type="submit">ANFRAGEN</button>
\t </fieldset>
</form>
anfrage.php
はこのようになりますこのようなEMail:
To: [email protected]
From: [email protected]
Subject:
Body:
Firma:
Ansprechpartner: Herr 59d4f7714f4d7
Adresse:
Telefonnummer:
Anfrage:
Sometiesそれは1日に1つの電子メールですが、時には30+です。
私はなぜそれらのEMailを取得し続けるのか分かりません。 これを避ける方法はありますか? または、anfrage.phpにセキュリティ上の問題がどこにあるか知っていますか?
ありがとうございます!
とにかく迷惑メールであることが分かっているので、最初に行ったことはキャプチャ(基本的なもの)でなければなりません。 - フォーム・チェック・ロジックはちょっと難しいです。あまりにも多くのローカルバール。代わりに '$ _POST'で直接作業し、関数を実行して最終的なテンプレートを生成するためにハッシュを使用する必要があります。 - その他:POST値と最終的な$ body結果を含むログファイルを作成します。 – mario