2014-10-29 82 views
-3

您能否看看我的代碼並回答問題:爲什麼我會收到空​​的電子郵件?我試着做了很多事情,但似乎沒有任何幫助:)反饋表格發送空的電子郵件

<?php 
mb_internal_encoding('UTF-8'); 
mb_http_output('UTF-8'); 
mb_http_input('UTF-8'); 
mb_language('uni'); 
mb_regex_encoding('UTF-8'); 
ob_start('mb_output_handler'); 
$field_name = $_POST['cf_name']; 
$field_email = $_POST['cf_email']; 
$field_message = $_POST['cf_message']; 

$mail_to = '[email protected]'; 
$subject = 'Сообщение от посетителя сайта '.$field_name; 

$body_message = 'От: '.$field_name."\n"; 
$body_message .= 'Электронный ящик: '.$field_email."\n"; 
$body_message .= 'Сообщение: '.$field_message; 

$headers = 'From: '.$field_email."\r\n"; 
$headers .= 'Reply-To: '.$field_email."\r\n"; 

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

if ($mail_status) { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('the message was sent.'); 
     window.location = 'contact.html'; 
    </script> 
<?php 
} 
else { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('the message was not sent.'); 
     window.location = 'contact.html'; 
    </script> 
<?php 
} 
?> 

和這裏的HTML:

<form action="contact.php" method="post"> 
        <div class="templatemo_form"> 
    <input name="cf_name" type="text" class="form-control" id="cf_name" placeholder="your name" maxlength="40"> 
</div> 
<div class="templatemo_form"> 
    <input name="field_email" type="text" class="form-control" id="field_email" placeholder="your e-mail" maxlength="40"> 
</div> 
<div class="templatemo_form"> 
    <textarea name="field_message" rows="10" class="form-control" id="field_message" placeholder="Message"></textarea> 
</div> 
<div class="templatemo_form"><button type="submit" value="Send" class="btn btn-primary">Send</button></div> 

非常感謝。 Radik

+0

[HTML5佔位符屬性不是標籤元素的替代品](http://www.456bereastreet.com/archive/201204/the_html5_placeholder_attribute_is_not_a_substitute_for_the_label_element/) – Quentin 2014-10-29 10:26:50

+0

告訴我們您嘗試了什麼,並向我們展示出現問題的代碼...看看[問];) – mithrop 2014-10-29 10:26:59

+0

您是否嘗試過將表單中的'name'值與您在PHP中解析的內容進行匹配? – 2014-10-29 10:27:03

回答

0

你的HTML說:

name="field_message" 

你的PHP說:

$_POST['cf_message']; 

,如果你從一個不同的名字讀它不工作,然後你送。

+0

這隻會導致電子郵件中缺少部分,而不是完全空白的郵件。 – 2014-10-29 10:28:32