2017-10-04 10 views
1

저는 PHP에 익숙하지 않습니다. 이메일을 보내려면 홈페이지에 간단한 양식을 사용하고 있습니다.PHP 메일()을 철저히 확인했지만 빈 메일을받습니다.

<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은 다음과 같습니다 : 이럴 빈 이메일 내게 통해 얻을해야하지만

<?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(); 
?> 

, 내가 점점 계속

양식입니다 다음과 같은 이메일 :

To: [email protected] 
From: [email protected] 
Subject: 
Body: 
Firma: 
Ansprechpartner: Herr 59d4f7714f4d7 
Adresse: 
Telefonnummer: 
Anfrage: 

Someties 하루에 단지 하나의 이메일입니다. 때로는 30 이상입니다.
나는 왜 나는 그 전자 메일을 계속 받고 있는지 잘 모른다. 피하는 방법을 알고 있습니까? 또는 anfrage.php에 보안 문제가있는 곳을 알고 계십니까?

미리 감사드립니다.

+0

어쨌든 스팸이라는 것을 알기에 첫 번째 시도는 보안 문자 (기본 사항) 여야합니다. - 양식 검사 논리는 따라 가기가 조금 어렵습니다. 너무 많은 로컬 바. '$ _POST'에서 직접 작업하고 함수를 통해 /을 실행하고 최종 템플릿을 생성하기 위해 일부 해시를 사용해야합니다. - 그렇지 않으면 : POST 값과 최종 $ body 결과로 로그 파일을 만들도록하십시오. – mario

답변

1

checkFormCompletion 함수에 오타가 있으므로 항상 필드를 비어있는 것으로 평가합니다.

function checkFormCompletion($str_to_test){ 
    contains_bad_str($str_to_test); 
    if(isEmpty($str_totest)){ // $str_totest should be $str_to_test 

PHP에는 변수가 비어 있는지 확인하는 기능이 있습니다. 맞습니까? empty

+0

대단히 고마워요 ... 나는 driectly 시도해 줘! 하지만 항상이 이메일을 보내지 않도록해야합니까? – Mario

+0

솔직히 말해서 양식을 살균하는 양식을 파악하려고 할 수 없습니다. requestb.in을 설정하고 해당 URL에서 양식 작업을 가리키면 양식이 예상되는 값을 게시 하시겠습니까? 그렇다면 위생 처리 과정이 중단됩니다. 개인적으로는 처음부터 다시 시작해야 할 것입니다. 양식 소독은 중요합니다. PHP는 이미 내장 된 입력을 위생 처리하는 많은 기능을 가지고 있습니다. http://php.net/manual/en/filter.filters.sanitize.php 참조 – miknik

+0

오타가 원인이었습니다. 문제의 ...-) 그럼에도 불구하고 나는 당신이 내받은 데이터를 sanitize하기 위해 지적한 php 함수 중 일부를 사용한다. THX! – Mario