2012-12-12 66 views
1

我已經實現了一個表單,可以將提交的信息成功發送到我的電子郵件。除了複選框,我可以通過所有輸入來實現此目的。爲了使複選框值也顯示在我的電子郵件中,我需要做些什麼?我試圖用每個循環,但我不知道我是否沿着正確的路線。以下相關代碼:從提交的表格中收到電子郵件中的複選框信息

代碼:

$companyname = $_POST['companyname']; 
$fullname = $_POST['fullname']; 
$email = $_POST['email']; 
$phonenumber = $_POST['phonenumber']; 

foreach($_POST['check'] as $value) { 
$check_msg .= "Checked: $value\n"; 
} 

$to = '[email protected]'; 
$subject = 'Quote'; 
$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname.  "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '$check_msg; 

HTML:

<label><input type="checkbox" name="check[]" id="q12_1" value="E commerce Shopping Cart" />E-commerce (Shopping Cart)</label> 
<label><input type="checkbox" name="check[]" id="q12_2" value="Content Management System CMS" />Content Management System (CMS)</label> 
+1

您不包括'$ check_msg的'在'$ message'中。另外,使用'!empty'。 http://stackoverflow.com/questions/2268887/php-checkbox-input – Vucko

+0

對不起,我包括它,我只是忘了添加它。請參閱修訂 - 仍然無效... – user1278496

+1

'$ check_msg。=「檢查:」。$ value。「\ n」;' – Vucko

回答

2

嘗試:

$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname. "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '.$check_msg;

你失蹤的.'Features: '

例如,這個工程:

<?php 

$companyname = $_POST['companyname']; 
$fullname = $_POST['fullname']; 
$email = $_POST['email']; 
$phonenumber = $_POST['phonenumber']; 

foreach ($_POST['check'] as $value) { 
    $check_msg .= "Checked: $value\n"; 
} 

$to = '[email protected]'; 
$subject = 'Quote'; 
$message = 'Company Name: '.$companyname. "\n"."\n". 'Full Name: ' .$fullname.  "\n"."\n". 'E-mail: '.$email. "\n"."\n". 'Phone Number: '.$phonenumber. "\n"."\n". 'Features: '.$check_msg; 
echo $message; 
?> 
<form action='' method="post"> 
    <label> 
     <input type="checkbox" name="check[]" id="q12_1" value="E commerce Shopping Cart" /> 
     E-commerce (Shopping Cart)</label> 
    <label> 
     <input type="checkbox" name="check[]" id="q12_2" value="Content Management System CMS" /> 
     Content Management System (CMS)</label> 
    <input type="submit" value="submit"> 
</form> 
1

嘗試這樣的。

if(!empty($_POST['check'])) { 
    foreach($_POST['check'] as $value) { 
     $check_msg .= "Checked:".$value."\n";    
    }} 
相關問題