2016-11-02 89 views
0

我正在創建一個具有單選按鈕,複選框和文本區域字段的聯繫表單。當我點擊提交按鈕時,我會收到我的電子郵件中的所有值除了複選框。以下附件是我的PHP和HTML代碼片段,請協助?當檢查發送多個複選框數組到電子郵件

<?php 

//INITIALIZE VARIABLES and set to empty values 
$checkbox = ""; 

if ($_SERVER["REQUEST_METHOD"] == "POST") { 

    // Check the values from checkbox and POST them to email 
    if(!empty($_POST["checkbox"]))       //check if the user has selected a CHECKBOX or NOT 
     { 
     $checkbox =$_POST["checkbox"];    //Array of values from the checkbox 

     foreach($checkbox as $value)    //loop to store and display values of individual checkboxes 
     {echo $value;}}       //Display selected checkbox 
     else {test_input($_POST["value"]);}  //POST values to email 

//HTML CODE 

What project would you like for your business venture? <span class= "error"> * </span> 
<br> <br> <input type="checkbox" class="input" name="checkbox[]" value="Graphics Design"> Graphics Design (Book, Posters, Flyers, Banners, Magazines, T-Shirts) <br> 
<input type="checkbox" class="input" name="checkbox[]" value="Logo Design"> Professional logo Design <br> 
<input type="checkbox" class="input" name="checkbox[]" value="Branding"> Branding <br> 
<input type="checkbox" class="input" name="checkbox[]" value="Digital Marketing" > Digital Marketing (Social-Media Marketing, E-Mail Marketing & SEO) 

<button class="submit" type= "reset" value= "Reset"> Reset Form </button> 
<button class="submit" type= "submit" value= "Submit"> Submit Form </button> 
+1

複選框,纔會發送。 – PeeHaa

+0

要發送電子郵件的哪些功能,請至少分享一行。 – C2486

回答

0
<?php 
$firstname = $_POST["firstname"]; 
$lastname = $_POST["lastname"]; 
$email = $_POST["email"]; 
$message = $_POST["message"]; 

if($_POST["email"]){ 
$ToEmail = 'required email ID'; 
$EmailSubject = 'Request from contactus page'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]; 
$MESSAGE_BODY = ' Contact from : '.$firstname.' '.$lastname."\r\n"; 
$MESSAGE_BODY .='Email : '.$email."\r\n"; 
$MESSAGE_BODY .='Message : '.$message."\r\n"; 
$MESSAGE_BODY .= 'Interested in :'."\r\n"; 
if (isset($_POST['checkbox-name']) && !empty($_POST['checkbox-name']))  { 
foreach($_POST['checkbox-name'] as $selected){ 
$MESSAGE_BODY .= $selected."\r\n"; 
} 
} 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die  ("Failure"); 
echo "Your message was sent"; 
} 
else{ 
echo "SOrry , No mail was sent"; 
} 
?> 
相關問題