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>

I would begin by making sure that you sanitize input passed in via $_POST. This ensures that someone doesn't pass in something like $POST['oneway'] = '</p>Foo!<strong>Blah</strong> and completely screw up your HTML, or, worse yet, inject Javascript into your HTML.

    <p><b>One Way:</b> ' . htmlspecialchars($oneway) . '</p>
    <p><b>Return:</b> ' . htmlspecialchars($return) . '</p>

Can you please clarify what isn't working as intended? I don't see anything in your code having anything to do with PHPMailer, so I'm a bit confused.

Why do you have <form action="#errors"? Typically, the form action would be a PHP page that processes the form.

What is the form trying to accomplish? Currently, we have these two POST fields being passed into this PHP page, and we're using them to set the values of a form that loads on the page. For what purpose? Is there a different form that is used to pass in the values of oneway and return?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.