2011-11-28 66 views
0

我已經爲我的網站創建了一個大型表單,並且我嘗試對php進行編碼以獲取表單中輸入的信息。但是,當用戶提交我在電子郵件中收到的唯一消息是消息正文,並且用戶的信息不存在。這是形式的代碼:表單不提交信息到電子郵件

<div id="stylized" class="myform"> 
<form id="myform" name="myform" action="bookingform.php"> 
<h1></h1> 
<p></p> 

<div id="firstname"> 
<label>Name 
<span class="small">Add your name</span> 
</label> 
<input type="text" name="FirstName" id="FirstName" /> 
</div> 

<div id="email"> 
<label>Email 
<span class="small">Add a valid email address</span> 
</label> 
<input type="text" name="Email" id="Email" /> 
</div> 

<div id="phone"> 
<label>Tel Number 
<span class="small">Add phone number</span> 
</label> 
<input type="text" name="Phone" id="Phone" /> 
</div> 


<label>Address 
<span class="small">Add your address</span> 
</label> 
<input type="text" name="Address" id="Address" /> 


<h2 style="margin-top:140px;">Event Venue Information</h2> 

<div id="dates"> 
<label>Date of Event 
<span class="small">Date of your occasion</span> 
</label> 
<input type="text" name="datex" id="datex" /> 
</div> 
<div> 
<label>Occasion 
<span class="small">Type of occasion</span> 
</label> 
<input type="text" name="type" id="type" /> 
</div> 

<div style="margin-left:315px;"> 
<label>Venue 
<span class="small">Location of event</span> 
</label> 
<input type="text" name="location" id="location" /> 
</div> 
<div style="float:right; margin-right:25px;"> 
<label>Services Required 
<span class="small">Service needed</span> 
</label> 
<textarea cols="40" rows="5" name="services"> 
</textarea> 
</div> 


<div style="margin-top:-20px;"> 
<label>Please photo's that you find are useful:</label> 
<input type="file" name="datafile" size="40" 
onchange="return validateFileExtension(this)"> 
<input type="file" name="datafile" size="40" 
onchange="return validateFileExtension(this)"> 
</div> 


<h2 style="margin-top:260px;">Additional Information</h2> 

<div style="margin-left:-40px; margin-top:30px;"> 
<label>How you found us? 
<span class="small">Website/DJ's/Friend</span> 
</label> 
<input type="text" name="found" id="found" /> 
</div> 

<div style="float:right; margin-right:10px;"> 
<label>Your comments/questions 
<span class="small">Any other queries</span> 
</label> 
<textarea cols="40" rows="5" name="questions"> 
</textarea> 
</div> 
<div> 
<input class="buttons" style="margin-top:10px; margin-left:110px;" type="submit" 
value="Submit" 
></input> 
</div> 

<div class="spacer"></div> 

</form> 
<script language="JavaScript" type="text/javascript" 
    xml:space="preserve">//<![CDATA[ 
//You should create the validator only after the definition of the HTML form 
    var frmvalidator = new Validator("myform"); 
    frmvalidator.addValidation("FirstName","req","Please enter your First Name"); 
    frmvalidator.addValidation("FirstName","maxlen=20", "Max length for FirstName is 20"); 
    frmvalidator.addValidation("FirstName","alpha","Alphabetic chars only"); 

    frmvalidator.addValidation("Email","maxlen=50"); 
    frmvalidator.addValidation("Email","req"); 
    frmvalidator.addValidation("Email","email"); 

    frmvalidator.addValidation("Phone","maxlen=50"); 
    frmvalidator.addValidation("Phone","numeric"); 

    frmvalidator.addValidation("Address","maxlen=50"); 

//]]></script> 
</div> 

這是PHP代碼:

<?php 
$boundary = uniqid('np'); 

$field_name = $_POST['FirstName']; 
$field_email = $_POST['Email']; 
$field_phone = $_POST['Phone']; 
$field_address = $_POST['Address']; 
$field_date = $_POST['datex']; 
$field_type = $_POST['type']; 
$field_location = $_POST['location']; 
$field_services = $_POST['services']; 
$field_found = $_POST['found']; 
$field_comments = $_POST['questions']; 

$mail_to = '[email protected]'; 


$body_message = 'From: '.$field_name."\n"; 
$body_message .= 'E-mail: '.$field_email."\n"; 
$body_message .= 'Phone: '.$field_phone."\n"; 
$body_message .= 'Address: '.$field_address."\n"; 
$body_message .= 'Date: '.$field_date."\n"; 
$body_message .= 'Type of Occasion: '.$field_type."\n"; 
$body_message .= 'Location: '.$field_location."\n"; 
$body_message .= 'Services required: '.$field_services."\n"; 
$body_message .= 'How they found us: '.$field_found."\n"; 
$body_message .= 'Comments - Questions: '.$field_comments; 

$headers = "MIME-Version: 1.0\r\n"; 
$headers = 'From: '.$Email."\r\n"; 

$headers .= "Content-Type: multipart/alternative;boundary=" . $boundary . "\r\n"; 


$message = "This is a MIME encoded message."; 

$message .= "\r\n\r\n--" . $boundary . "\r\n"; 
$message .= "Content-type: text/plain;charset=utf-8\r\n\r\n"; 
$message .= "This is the text/plain version."; 

$message .= "\r\n\r\n--" . $boundary . "\r\n"; 
$message .= "Content-type: text/html;charset=utf-8\r\n\r\n"; 
$message .= "This is the <b>text/html</b> version."; 

$message .= "\r\n\r\n--" . $boundary . "--"; 



$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 = 'http://www.hrsevents.co.uk'; 
    </script> 
<?php 
} 
else { ?> 
    <script language="javascript" type="text/javascript"> 
     alert('Message failed. Please, send an email to [email protected]'); 
     window.location = 'url'; 
    </script> 
<?php 
} 
?> 

我將不勝感激,如果有人可以幫助我這個,因爲我完全被卡住。

感謝

回答

4

您需要設置窗體屬性method="post"。如果沒有該屬性,當您的PHP代碼嘗試獲取POST數據時,表單將自動提交爲GET請求。

相關問題