我正在创建一个联系表单,其中包含单选按钮,复选框和文本区域字段。当我点击提交按钮时,我会在电子邮件EXCEPT复选框中获取所有值。下面是我的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>
答案 0 :(得分: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";
}
?>