2014-10-19 51 views
0

當我提交我的html表單時,我只能在我的電子郵件中獲得$ name值。另外,當我點擊提交而不是重定向到我的謝謝html頁面時,謝謝頁面的內容出現在表單下。任何想法爲什麼?這裏是我的代碼...PHP Form only emails 1 value

HTML:

<section class="container content"> 

<div class="row"> 
<div class="center title col-sm-12"> 
<h2>Short Application Form</h2> 
</div> 
</div> 

<h2>Personal Information</h2> 
<form method="post" action="appemail.php" name="contactform" id="contactform" class="row"> 
<fieldset> 
<div class="form-field col-sm-6"> 
<label for="name">First Name</label> 
<span><input type="text" name="name" id="name"/></span> 
</div> 

<div class="form-field col-sm-6"> 
<label for="lastname">Last Name</label> 
<span><input type="text" name="lastname" id="lastname"/></span> 
</div> 

<div class="form-field col-sm-6"> 
<label for="email">Email</label> 
<span><input type="text" name="email" id="email"/></span> 
</div> 

<!--<div class="form-field col-sm-6"> 
<label for="email">Referral Name</label> 
<span><input type="email" name="email" id="email"/></span> 
</div>--> 

<div class="form-field col-sm-6"> 
<label for="email">Home/Cell Phone</label> 
<span><input type="text" name="phone" id="phone"/></span> 
</div> 

<div class="form-field col-sm-6"> 
<label>Martial Satus</label> 
<select name="martial"> 
    <option>Married</option> 
    <option>Unmaried</option> 
    <option>Seperated</option> 
</select> 
</div> 

<div class="form-field col-sm-6"> 
<label>Are you a Canadian Permanent Resident</label> 
<select name="resident"> 
    <option>Yes</option> 
    <option>No</option> 
</select> 
</div> 

<div class="form-field col-sm-6"> 
<label for="email">Date of Birth</label> 
<span><input type="text" name="birth"/></span> 
</div> 

<div class="form-field col-sm-6"> 
<label for="email">Number of Dependents</label> 
<span><input type="text" name="dependents"/></span> 
</div> 

<div class="center title col-sm-12"> 
<h2 style="text-align:left">Current Address</h2> 
</div> 

<div class="form-field col-sm-6"> 
<label for="name">Street Address</label> 
<span><input type="text" name="adress"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">City</label> 
<span><input type="text" name="city"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">Province</label> 
<span><input type="text" name="province"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">Postal Code</label> 
<span><input type="text" name="postal"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">Years at this Address</label> 
<span><input type="text" name="years"/></span> 
</div> 

<div class="form-field col-sm-6"> 
<label>Rent or Own</label> 
<select name="rent"> 
    <option>Own</option> 
    <option>Rent</option> 
</select> 
</div> 

<div class="center title col-sm-12"> 
<h2 style="text-align:left">Subject Property</h2> 
</div> 

<div class="form-field col-sm-6"> 
<label>Property Usage</label> 
<select name="property"> 
    <option>Primary Residence</option> 
    <option>Second Home</option> 
    <option>Investment</option> 
</select> 
</div> 

<div class="form-field col-sm-6"> 
<label for="name">Loan Amount $ </label> 
<span><input type="text" name="loan"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">Purchase Price $</label> 
<span><input type="text" name="price"/></span> 
</div> 

<div class="center title col-sm-12"> 
<h2 style="text-align:left">Monthly Income</h2> 
</div> 

<div class="form-field col-sm-6"> 
<label for="name">Yearly Income $ </label> 
<span><input type="text" name="yearly"/></span> 
</div> 
<div class="form-field col-sm-6"> 
<label for="name">Other Sources of Income (combined) $</label> 
<span><input type="text" name="other"/></span> 
</div> 

<div class="form-field col-sm-12"> 
<label for="message">Comments</label> 
<span><textarea name="message" id="message"></textarea></span> 
</div> 
</fieldset> 
<div class="form-click center col-sm-12"> 
<span><input type="submit" name="submit" id="submit" value="Send it"/></span> 
</div> 
<div id="alert" class="col-sm-12"></div> 
</form> 
</section> 

PHP:

<?php 

$name = $_POST['name']; 
$lastname = $_POST['lastname']; 
$visitor_email = $_POST['email']; 
$phone = $_POST['phone']; 
$martial = $_POST['martial']; 
$resident = $_POST['resident']; 
$birth = $_POST['birth']; 
$dependents = $_POST['dependents']; 
$adress = $_POST['adress']; 
$city = $_POST['city']; 
$province = $_POST['province']; 
$postal = $_POST['postal']; 
$years = $_POST['years']; 
$rent = $_POST['rent']; 
$property = $_POST['property']; 
$loan = $_POST['loan']; 
$price = $_POST['price']; 
$other = $_POST['other']; 
$message = $_POST['message']; 

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

$email_from = $visitor_email; 
$email_subject = "Application Loan"; 

$email_body = "You have received a new message from $name\n\n". 
    "Here is the Application: \n\n". 
    "Phone: $phone\n\n". 
    "Martial Status: $martial\n\n". 
    "Resident: $resident\n\n". 
    "Birth: $birth\n\n". 
    "Dependents: $dependents\n\n". 
    "Address: $address\n\n". 
    "City: $city\n\n". 
    "Province: $province\n\n". 
    "Postal: $postal\n\n". 
    "Years at this Address: $years\n\n". 
    "Rent or Own: $rent\n\n". 
    "Property: $property\n\n". 
    "Loan: $loan\n\n". 
    "Price: $price\n\n". 
    "Other: $other\n\n". 
    "Message: $message\n\n"; 

$to = "[email protected]";//<== update the email address 
$headers = "From: $visitor_email \r\n"; 
$headers .= "Reply-To: $visitor_email \r\n"; 

//Send the email! 
mail($to,$email_subject,$email_body,$headers); 
//done. redirect to thank-you page. 
header('Location:thank-you.html'); 
// Function to validate against any email injection attempts 

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;} 
} 
?> 

在此先感謝。

+1

武術 - >婚姻:) – jimmy 2014-10-19 08:15:01

+0

你真的應該關心字符編碼/轉義。否則,您的電子郵件可能會被轉發服務器改變和修改。 – arkascha 2014-10-19 08:15:21

回答

0

由於換行符,串連不起作用。

0

重寫你的代碼並使用<br>,除了\n &當使用isset函數提交表單檢查數據時,添加一個隱藏字段來做它。

+0

語法看起來如何與
?謝謝你將添加isset函數。 @Patricia – hassaad 2014-10-19 15:14:03

0

我已經複製了你的代碼,它運行良好,除了你有一個錯誤的$地址。 有時你使用地址(這是正確的),有時候是地址。

電子郵件我收到:

You have received a new message from First Name 
Here is the Application: 
Phone: 0000000 
Martial Status: Married 
Resident: Yes 
Birth: 2014-10-19 
Dependents: 42 
Address: Street Address 
City: City 
Province: Province 
Postal: Postal Code 
Years at this Address: 42 
Rent or Own: Own 
Property: Primary Residence 
Loan: 42 
Price: 42 
Other: 42 
Message: Comments 

線的新的顯示將與大多數電子郵件客戶端工作,因爲沒有html標籤,所以它會顯示爲純文本。 Setting the appropriate header也有幫助。

否則,你的後端是什麼? 操作系統,主機,PHP版本?

+0

我已經嘗試更改標題,但我仍然只獲取名稱值。我也注意到,即使我改變它只發送1變量,唯一的作品是$ name ...我會嘗試獲取主機信息。 「您收到一封新郵件從MYNAME 這裏是應用程序: 電話: 婚姻狀況: 居民: 出生: 家屬: 地址: 城市: 省: 郵政: 年在這個地址: 出租或自己: 物業: 貸款: 價格: 其他: 消息:」 – hassaad 2014-10-19 12:47:51

+0

設置在接收PHP腳本的頭會不會影響它得到作爲輸入POST數據。總之,這不太可能是問題所在。 由於你提供了或多或少的作品(軍事,地址)的代碼,所以你的環境會有一些腥意。 你使用任何框架(蛋糕,symfony,燃料等)? 'phpinfo();'顯示哪些版本? – lazos 2014-10-21 17:19:18