2013-10-11 5 views
-1
<?php 
$name = $_POST['name']; 
$email = $_POST['email']; 
$phone = $_POST['phone']; 
$priority = $_POST['priority']; 
$type = $_POST['type']; 
$website = $_POST['website']; 
$message = $_POST['message']; 

$mail_to = '[email protected]'; 
$subject = 'Message from a site visitor '.$subject; 

$body_message = "From: $name\n"; 
$body_message .= "E-mail: $email\n"; 
$body_message .= "Phone: $phone\n"; 
$body_message .= "Priority: $priority\n"; 
$body_message .= "Type: $type\n"; 
$body_message .= "Website: $website\n"; 
$body_message .= "Message: $message"; 

$headers = "From: $email"; 
$headers .= "Reply-To: $email"; 

$mail_status = mail($mail_to, $subject, $body_message, $headers); 

if ($mail_status) { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('Thank you for the message. We will contact you shortly.'); 
     window.location = 'contact_page.html'; 
    </script> 
<?php 
} 
else { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('Message failed. Please try '); 
     window.location = 'contact_page.html'; 
    </script> 
<?php 
} 
?> 

이것은 PHP 파일이지만 시도 할 때마다 메시지를받을 수 있지만 입력 값은 포함되어 있지 않습니다.이 PHP를 문의 양식에 사용하고 있는데 입력을 인식하지 못합니다.

수신 된 이메일처럼 보이는이

From: 
E-mail: 
Phone: 
Priority: 
Type: 
Website: 
Message: 

누군가가 내 문제를 도와 줄 수 있습니까?

감사합니다.

+1

이 함께가는 HTML을 게시하시기 바랍니다 .. 대신 $_POST$_REQUESTsprintf를 사용하여 좀 덜 보안 해제를 시도 할 수 . –

+0

나는 마이크 밑에 html을 올렸다. – user2869403

+0

감사합니다.하지만 아마도 조금 늦었습니다. –

답변

0

당신은

<?php 
$name = $_REQUEST['name']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['phone']; 
$priority = $_REQUEST['priority']; 
$type = $_REQUEST['type']; 
$website = $_REQUEST['website']; 
$message = $_REQUEST['message']; 

$mail_to = '[email protected]'; 
$subject = sprintf("Message from a site visitor %s\n", $subject); 

$body_message = sprintf("From: %s\n", $name); 
$body_message .= sprintf("E-Mail: %s\n", $email); 
$body_message .= sprintf("Phone: %s\n", $phone); 
$body_message .= sprintf("Priority: %s\n", $priority); 
$body_message .= sprintf("Type: %s\n", $type); 
$body_message .= sprintf("Website: %s\n", $website); 
$body_message .= sprintf("Message: %s\n", $message); 

$headers = sprintf("From: %s\n", $email); 
$headers .= sprintf("Reply-To: %s\n", $email); 

$mail_status = mail($mail_to, $subject, $body_message, $headers); 

if ($mail_status) { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('Thank you for the message. We will contact you shortly.'); 
     window.location = 'contact_page.html'; 
    </script> 
<?php 
} 
else { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('Message failed. Please try '); 
     window.location = 'contact_page.html'; 
    </script> 
<?php 
} 
?> 
+0

코드에서

나는 method = "REQUEST"를 사용해야합니까? 덕분에 – user2869403

+0

내 질문에 대한 답변을 생각합니다. 고마워 친구! – user2869403

+0

하지만 내 유일한 문제는 @이 @@ %로 보내지지 않고 있다는 것입니다. 어떻게 바꾸는거야? – user2869403

0

저에게 먼저 HTML 표시.

양식에 method="post"을 설정했는지 확인하십시오. 또한 입력의 이름을 확인하십시오. POST 배열의 변수와 일치해야합니다. $_REQUEST 다른 사람의 모두 postget 다양한에 보이는 것 때문에

+0

친절하게 html로 게시했습니다. 덕분에 – user2869403

0
<form id="contact-form" action="mail.php" method="POST"> 
      <h3>Get in touch</h3> 
      <h4>Fill in the form below, and we'll get back to you within 24 hours.</h4> 
      <div> 
       <label> 

        <span>Name: (required)</span> 
        <input placeholder="Please enter your name" type="text" name="name" required autofocus> 
       </label> 
      </div> 
      <div> 
       <label> 
        <span>Email: (required)</span> 
        <input placeholder="Please enter your email address" type="email" name="email" tabindex="2" required> 
       </label> 
      </div> 
      <div> 
       <label> 
        <span>Telephone: (required)</span> 
        <input placeholder="Please enter your number" type="tel" name="phone" tabindex="3" required> 
       </label> 
      </div> 
      <div> 
       <label> 
        <span>What do you look for? (required)</span> 
        <select name="priority" size="1"> 
        <option value="Low">Choose from these</option> 
        <option value="Normal">Option 1</option> 
        <option value="High">Option 2</option> 
        <option value="Emergency">Option 3</option> 
        </select>    </label> 
      </div> 
      <div> 
       <label> 
        <span>Type: (required)</span> 
        <select name="type" size="1"> 
        <option value="update">Personal</option> 
        <option value="change">Small Business</option> 
        <option value="addition">Professional</option> 
        </select> 
       </label> 
      </div> 

      <div> 
       <label> 
        <span>Website: (required)</span> 
        <input placeholder="Begin with http://" type="url"name="website" tabindex="4" > 
       </label> 
      </div> 
      <div> 
       <label> 
        <span>Message: (required)</span> 
        <textarea placeholder="Include all the details you can" tabindex="5" name="message" required></textarea> 
       </label> 
      </div> 
      <div> 
       <button name="submit" type="submit" id="contact-submit" value="send">Send Email</button> 
      </div> 
     </form> 
관련 문제