ethanfox27 ethanfox27 - 1 year ago 62
HTML Question

Certain FormFiled not in body of email

Ok so I have this form made out, and it is set to go to my email. The form sends, but it only shows the bottom two fields in the emails. As you can see in the code below there are 5 fields. How can i make to where I recvieve the info for all of the field?


<form id="ajax-contact" method="post" action="../js/mailer.php">

<div class="field">
<select id="select" name="interest" title="Interested in ..." class="selectpicker">
<option value="NA">Interested in...</option>
<option value="Website">Website</option>
<option value="Web Design"> Only Web Design</option>
<option value="Brand Consulting">Brand Consulting</option>

<div class="field">
<input name="name" placeholder="Name:" type="text" id="name" required>

<div class="field">
<input name="email" placeholder="Email: " type="email" id="email"required>
<div class="field">
<div class="wrapper">
<div id="radio" class="toggle_radio">
<input value="$4k" type="radio" class="toggle_option" id="first_toggle" name="budget">
<input value="$5k - $9k" type="radio" checked class="toggle_option" id="second_toggle" name="budget">
<input value="$10k+" type="radio" class="toggle_option" id="third_toggle" name="budget">

<label for="first_toggle"><p>>$4k</p></label>
<label for="second_toggle"><p>$5k - $9k</p></label>
<label for="third_toggle"><p>$10k+</p></label>
<div class="toggle_option_slider">

<div class="field">
<textarea placeholder="project description(optional)" id="message" name="message" required></textarea>

<div class="field">
<button id="button" type="submit">SEND REQUEST</button>


// My modifications to mailer script from:
// Added input sanitizing to prevent injection

// Only process POST reqeusts.
// Get the form fields and remove whitespace.
$option = $_POST['interest'];
$name = $_POST['name'];
$email = $_POST['email'];
$rdb_value = $_POST['budget'];
$message = trim($_POST["message"]);

// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
echo "Oops! There was a problem with your submission. Please complete the form and try again.";

// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "EMAIL GOES HERE";

// Set the email subject.
$subject = "New Request from: $name";

// Build the email content.
$email_content = "Interested in: $option\n";
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content = "Budget: $rdb_value\n";
$email_content .= "Message:\n$message\n";

// Build the email headers.
$email_headers = "From: $name <$email>";

// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
// Set a 200 (okay) response code.
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
echo "Oops! Something went wrong and we couldn't send your message.";

} else {
// Not a POST request, set a 403 (forbidden) response code.
echo "There was a problem with your submission, please try again.";


Answer Source

Do you see the missing concatenates/dots in here?

// Build the email content.
$email_content = "Interested in: $option\n";
$email_content  = "Name: $name\n";
               ^ there
$email_content .= "Email: $email\n\n";
$email_content  = "Budget: $rdb_value\n";
               ^ and there
$email_content .= "Message:\n$message\n";

That broke "the chaining".

Add them:

// Build the email content.
$email_content = "Interested in: $option\n";
$email_content .= "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Budget: $rdb_value\n";
$email_content .= "Message:\n$message\n";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download