2014-06-12 3 views
-1

당신이 도울 수 있기를 바랍니다.구문 오류가 없지만 php 전자 메일 양식이 계속 실패합니다.

내 웹 사이트의 2 개 장소에서 구현 된 코드가 있습니다.

어떤 이유로 양식이 매번 전송되지 않습니다. 아래 코드는 구문 검사기를 통해 실행했으며 문제가되는 한 괜찮습니다.

<?php 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $number = $_POST['number']; 
    $message = $_POST['message']; 
    $from = 'From: Roofing Solutions Contact Form'; 
    $to = '[email protected]'; 
    $subject = 'Question Sent From Website Form'; 
    $human = $_POST['human']; 

    $body = "From: $name\n E-Mail: $email\n Number: $number\n Message:\n $message"; 

    if ($_POST['submit'] && $human == '4') {     
     if (mail ($to, $subject, $body, $from)) { 
      echo '<p>Your message has been sent!</p>'; 
     } else { 
      echo '<p>Something went wrong, go back and try again!</p>'; 
     } 
    } else if ($_POST['submit'] && $human != '4') { 
     echo '<p>You answered the anti-spam question incorrectly!</p>'; 
    } 
?> 

그래서 나는 그것에 대해 당황하고 있습니다. 그리고 safetys를 위해서, 여기에 html 형식이 있습니다 :

<form method="post" action="contactform.php"> 

    <label>Name</label> 
    <input name="name" placeholder="Type Here"> 

    <label>Email</label> 
    <input name="email" type="email" placeholder="Type Here"> 

    <label>Contact Number</label> 
    <input name="number" placeholder="Type Here"> 

    <label>Message</label> 
    <textarea name="message" placeholder="Type Here"></textarea> 

    <label>*What is 2+2? (Anti-spam)</label> 
    <input name="human" placeholder="Type Here"> 

    <input id="submit" name="submit" type="submit" value="Submit"> 

</form> 

감사합니다.

+1

귀하의'$의 from' 무서운 보인다. – urzeit

+0

-1 (http://stackoverflow.com/questions/23828423/php-form-doesnt-work?rq=1 –

+0

)에서 헤더가 헤더에 있어야합니다. 이 페이지의 예제 2를 참조하십시오. http://php.net/manual/en/function.mail.php –

답변

0
add header part.. 
/To send HTML mail, the Content-type header must be set 
$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
0

본문 및 메시지로 수행하는 작업을 알지 못하는데 이상하게 보입니다. 양식 가장 일반적인 솔루션, 헤더에 있어야합니다 : 귀하의 PHP 부분 :

$to = '[email protected]'; 
$subject = 'Question Sent From Website Form'; 
$message = "E-Mail: ".$_POST['email']."\n<br />Number: ".$_POST['number']."\n<hr />Message:\n ".$_POST['message']; 
$headers = "From: Roofing Solutions Contact Form <".$to.">\r\n" ; 
$headers .= 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n" ; 

if ($_POST['submit'] && _POST['human'] == '4') { 
    if (mail ($to, $subject, $message, $headers)) { 
     echo '<p>Your message has been sent!</p>'; 
    } else { 
     echo '<p>Something went wrong, go back and try again!</p>'; 
    } 
} else if ($_POST['submit'] && _POST['human'] != '4') { 
    echo '<p>You answered the anti-spam question incorrectly!</p>'; 
} 
관련 문제