2016-01-30 83 views
-1

我試圖使用HTML表單發送包含PHP的電子郵件。以PHP形式發送電子郵件以提供空值

但是,當我收到電子郵件時,姓名和電子郵件字段始終爲空,我只收到郵件。

這裏的表單代碼:

<form class="form" id="contact" action="form-to-email.php" method="post"> 
<input class="name" type="text" id="name" placeholder="Name" required> 
<input class="email" type="email" id="email" placeholder="Email" required> 
<input class="phone" type="text" id="phone" placeholder="Phone No:"> 
<textarea class="message" name="message" id="message" cols="30" rows="10"  placeholder="Message" required></textarea> 
<input class="submit-btn" id="submitbtn" type="submit" value="SUBMIT"> 
</form> 

和PHP代碼:

$myemail = '[email protected]';//myemail 
$name =filter_input(INPUT_POST, 'name'); 
$email_address = filter_input(INPUT_POST, 'email'); 
$message = filter_input(INPUT_POST, 'message'); 



$to = $myemail; 

$email_subject = "Contact form submission: $name"; 

$email_body = "You have received a new message. ". 

" Here are the details:\n Name: $name \n ". 

"Email: $email_address\n Message: \n $message"; 

$headers = "From: $myemail\n"; 

$headers .= "Reply-To: $email_address"; 

mail($to,$email_subject,$email_body,$headers); 
+1

你失蹤'的名字和電子郵件領域name'屬性。 –

+0

name =「name」和email =「email」在您的html代碼中缺失 – Drone

回答

3

<input class="name"...是錯誤的,它應該是<input name="WHATEVER"

name財產上輸入你參考一下形成價值。