Everything is working properly, I'm having issue in $mail->body.
Issue is: if a user comes to the form and fill up only 2 text fields and submit that form, data will be record in database and an Email will be sent and all the other empty fields will also be shown on email. I dont want that empty fields.
I want only populated fields that contains data to be shown on email. empty fields should not be shown on email. How I can achieve this?
Any help will be appreciated...
Here is a php mailer code, where I have some issue.
<?php
    //Import PHPMailer classes into the global namespace
    //These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
if(isset($_POST['insert']))
    {
    //Load Composer's autoloader
    require 'phpmailer/Exception.php';
    require 'phpmailer/SMTP.php';
    require 'phpmailer/PHPMailer.php';
    //Create an instance; passing `true` enables exceptions
    $mail = new PHPMailer(true);
    try {
    //Server settings
                 
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host       = 'smtp.gmail.com';                       //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'hereIsEmail';                     //SMTP username
    $mail->Password   = '********';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
    //Recipients
    $mail->setFrom('hereIsEmail', 'Testing');       //mailer name
    $mail->addAddress('hereIsEmail', 'User');     //Add a recipient
   
    //Content
    $mail->isHTML(true);                                        //Set email format to HTML
    $mail->Subject = 'ABC';
    **$mail->Body    = 
    "First name : $firstname
    <br> Last name : $lastname
    <br> Company : $company
    <br> Email Address : $emailaddress
    <br> Phone Number : $phonenumber
    <br> Site Address : $siteaddress
    <br> Map Reference : $mapreference
    <br> Account No : $accountno
    <br> Order No : $orderno
    <br> Date Ordered : $dateordered
    <br> Date Required : $daterequired
    <br> Delivery/Pickup : $deliverypickup
    <br> Pickup Time : $pickuptime
    <br> Pass Up : $passup
    <br>10mmPLASTER_6000x1350 : $PLASTER_6000x1350_13mm
    <br>13mmPLASTER_6000x1200 : $PLASTER_6000x1200_13mm
    <br>BATTENS_129_6000 : $BATTENS_129_6000
    <br>BATTENS_301_6000 : $BATTENS_301_6000
    <br>BATTENS_308_6000 : $BATTENS_308_6000";
**
    $mail->send();
    echo 'Form Submitted Successfully';
    } catch (Exception $e) {
        echo "Form could not be sent. Mailer Error: {$mail->ErrorInfo}";
    } 
}
 
    