2011-05-06 3 views
0

많은 고통과 상심 끝에 PHP 전자 메일 양식을 작성했습니다. 그것이 누락 된 유일한 것은주의 또는 메시지입니다. 아무도 나를 도울 수 있습니까?PHP 전자 메일 양식 Thankyou 참고

<form name="email" method="post"> 
    <p> 
    <label for="name">Full Name</label> 
    <input type="text" name="name" id="name"> 
    </p> 
    <p> 
    <label for="email">Email Address</label> 
    <input type="text" name="email" id="email"> 
    </p> 
    <p> 
    <label for="phone">Phone Number</label> 
    <input type="text" name="phone" id="phone"> 
    </p> 
    <p> 
    <label for="subject">Subject</label> 
    <input type="text" name="subject" id="subject"> 
    </p> 
    <p> 
    <label for="message">Message<br> 
    </label> 
    <textarea name="message" id="message" cols="45" rows="5"></textarea> 
    </p> 
    <p><input type="submit" name="send" id="send" value="Submit"><input type="reset" name="send" id="send" value="Reset"> 
    </p> 
</form> 


<?php 

// Get the Variables 
    $name = $_POST['name']; 
    $visitor_email = $_POST['email']; 
    $phone = $_POST['phone']; 
    $subject = $_POST['subject']; 
    $message = $_POST['message']; 


// Validate against spammers 
function IsInjected($str) 
{ 
    $injections = array('(\n+)', 
      '(\r+)', 
      '(\t+)', 
      '(%0A+)', 
      '(%0D+)', 
      '(%08+)', 
      '(%09+)' 
      ); 

    $inject = join('|', $injections); 
    $inject = "/$inject/i"; 

    if(preg_match($inject,$str)) 
    { 
     return true; 
    } 
    else 
    { 
     return false; 
    } 
} 

if(IsInjected($visitor_email)) 
{ 
    echo "Bad email value!"; 
    exit; 
} 


// Compose the Email 
    $email_from = '[email protected]'; // Set a valid email address that the form can use 

    $email_subject = "New Form submission - $subject"; // Change the message subject here 

    $email_body = "You have received a new message from $name ($phone) .\n Here is the message:\n $message"; 


// Send The Email 
    $to = "[email protected]"; // Set a valid email address to send the form to 

    $headers = "From: $email_from \r\n"; 

    $headers .= "Reply-To: $visitor_email \r\n"; 

    mail($to,$email_subject,$email_body,$headers); 

?> 
+0

전자 메일 주소에서 불안정한 문자를 확인하는 것보다 '$ 메시지'를 살균하는 것이 더 걱정 스럽습니다. 스팸 발송자는 여전히 '합법적 인'주소를 사용하고 메가 바이트 상당의 페니스 환약과 러시아 신부의 쓰레기로 메시지를 채울 수 있습니다. –

답변

2
if(mail($to,$email_subject,$email_body,$headers)){ 
    echo "Thanks for your mail..."; 
} 
0

매우 간단합니다, 메일() 함수는 그래서이를 사용하여 true/false를 반환

echo mail($to, $email_subject, $email_body, $headers) ? 'Mail send' : 'Failed to send mail'; 

가 화면에 결과를 에코합니다. 그러나 메시지가 아래에 배치되는 것은 흔한 일이 아니므로 양식 위의 양식 작업을 추가 할 수 있습니다. 송신 작업을 수행 : 그렇다면, 후 요청이있는 경우 먼저 보내 위로 확인 (및 전자 mailadres이 거짓되지 않음)이 경우

if($_SERVER['REQUEST_METHOD'] == "POST" && !IsInjected($visitor_email)) { 
    // insert form action here 
} else { 
    if(IsInjected($visitor_email)) { 
    echo "False e-mail address supplied 
    } 
    // add form HTML code here (outside PHP tags ofcourse 
} 

: 또한 당신은이를 사용할 수 있습니다. 그렇지 않으면 잘못된 전자 메일에 대한 오류 메시지를 표시하고 양식을 표시하십시오.

물론 이것은 어리석은 증거가 아닙니다. 직접 작업해야합니다.

관련 문제