Home > database >  How to include default value with input data
How to include default value with input data

Time:07-30

So I built a php email form that allows users to submit inquiries which I got up and running, except there is one caveat. When the users enter their data and clicks submit, I get an email with the data they inputted but it ONLY shows the inputted data and not the value along with it. For example:

Email Form

Now this is the email that comes over:

enter image description here

So again, my question is how do I get the input values to show in addition to the users inputted data in the email that's received? Example of what I want:

Company Name: David
Number of Employees: 3
Current Coverage: None
Telephone Number: 123-456-7890
Location: New Jersey
Email Address: [email protected]

I hope this makes sense. Here is my email form code below as well:

HTML FORM

<form action="index.php"
              method="post"
              enctype="multipart/form-data"
              name="EmailForm">
                
                <input type="text" name="subject"  
                 value="New Quote Request" required="required" 
                 hidden>
                <label for="name">Company Name</label>
                <br>
                <input type="text" name="name"  
                 placeholder="Company Name" required="required">
                <br> 
                <label for="employees">Number of Employees</label>
                <br>
                <input type="number" name="employees"  
                 placeholder="# of Employees" required="required">
                <br>
                <label for="coverage">Current Coverage</label>
                <br>
                <input type="text" name="coverage"  
                 placeholder="Current Coverage" 
                 required="required">
                <br>
                <label for="telephone">Telephone Number</label>
                <br>
                <input type="text" name="telephone"  
                 placeholder="Telephone #" required="required">
                <br>
                <label for="email">Email Address</label>
                <br>
                <input type="email" name="email"  
                 placeholder="Email Address" required="required">
                <br>
                <label for="location">Location</label>
                <br>
                <input type="text"  
                 name="location" 
                 placeholder="Location" required="required">

                <br>

                <button type="submit" value="submit" >Submit</button>

                <br><br>
                </form>

PHP CODE

<?php

// get email from the config file
$config = require_once __DIR__ . '/../config/app.php';
$recipient_email = $config['mail']['to_email'];

// contact information
$company_name = $inputs['name'];
$employees = $inputs['employees'];
$coverage = $inputs['coverage'];
$telephone = $inputs['telephone'];
$location = $inputs['location'];
$contact_email = $inputs['email'];
$subject = $inputs['subject'];

// Email header
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=utf-8';
$headers[] = "To: $recipient_email";
$headers[] = "From: $contact_email";
$header = implode('\r\n', $headers);

$body = $message . "\n" . $company_name . "\n" . $employees . "\n" . $coverage . "\n" . $telephone . "\n" . $location . "\n" . $contact_email;
mail($recipient_email, $subject, $body, $header);

CodePudding user response:

The label text isn't transferred to the server along with the form data, that's not how HTML forms work.

So whatever text you want in your email, you have to include it yourself in the php code which generates that email.

  • Related