ianhaney10 Posted February 13 Share Posted February 13 I need some help with getting checkbox values sent to email using phpmailer I have not done it before so unsure how to do it, the current code I have is below $postData = $_POST; $oneway = $_POST['oneway']; $return = $_POST['return']; $htmlContent = '<h2>Contact Form Details</h2> <p><b>One Way:</b> ' . $oneway . '</p> <p><b>Return:</b> ' . $return . '</p> <form action="#errors" method="post" class="formontop"> <div class="booking-form"> <div class="row mb-4"> <div class="col-lg-6"> <div class="form-check"> <input type="checkbox" name="oneway" class="form-check-input" value="<?php echo !empty($postData['oneway'])?$postData['oneway']:''; ?>"> <label class="form-check-label" for="oneway"> One Way </label> </div> </div> <div class="col-lg-6"> <div class="form-check"> <input type="checkbox" name="return" class="form-check-input" value="<?php echo !empty($postData['return'])?$postData['return']:''; ?>"> <label class="form-check-label" for="return"> Return </label> </div> </div> <button class="default-btn" type="submit" name="submit">Get My Quote</button> </div> </div> </form> Quote Link to comment https://forums.phpfreaks.com/topic/326788-send-checkbox-value-to-email-using-phpmailer/ Share on other sites More sharing options...
mac_gyver Posted February 13 Share Posted February 13 only checked checkboxes are set in the submitted form data. for what you are doing, you should only be concerned if they are set or are not set, not what the value is (the default value will be the text 'on'). i recommend that make an array that defines the checkbox field names and labels, then loop over this defining array to dynamically produce the form fields, pre-checking any existing checked boxes, in the case of a user/validation error, then loop over this defining array in the post method form processing code, testing which one(s) are set or are not set in the form data to produce whatever result you want. 1 Quote Link to comment https://forums.phpfreaks.com/topic/326788-send-checkbox-value-to-email-using-phpmailer/#findComment-1649502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.