I began using a short template to create a PHP Mail Form for a quick way of getting volunteer information. However, each time I attempt to add new fields: Phone, Address and Help (checkboxes) they don’t come through via PHP mail.
Instead they show up blank, but the email does go through.
I’ve swapped out $php_id for $id, as well as eliminated ajax. Neither worked. Additionally, I attempted using “id” vs ‘ajax_id’ and that would not make any difference.
I’m sure this is something stupid that I just don’t understand, but I would appreciate any assistance you could provide so I can get this up and running for a friend.
HTML:
<form action="/" method="post" class="contact_form" id="contact_form">
<div class="returnmessage" data-success="Your message has been received, We will contact you soon."></div>
<div class="empty_notice"><span>Please Fill Required Fields</span></div>
<div class="first">
<ul>
<li>
<input id="name" type="text" placeholder="Name">
</li>
<li>
<input id="phone" type="tel" placeholder="Phone">
</li>
<li>
<input id="email" type="email" placeholder="Email">
</li>
<li>
<input id="address" type="text" placeholder="Address">
</li>
</ul>
How can you help?<br>
<p>
<label>
<input type="checkbox" name="help" value="doors" id="help_0">Knock Doors</label>
<br>
<label>
<input type="checkbox" name="help" value="bank" id="help_1">Phone Bank</label>
<br>
<label>
<input type="checkbox" name="help" value="sign" id="help_2">Host Yard Sign</label>
<br>
<label>
<input type="checkbox" name="help" value="fund" id="help_3">Plan Fundraiser</label>
<br>
<label>
<input type="checkbox" name="help" value="meet" id="help_4">Set Up Meet and Greet</label>
<br>
</p><br>
</div>
<div class="last">
<textarea id="message" placeholder="Message"></textarea>
</div>
<div class="grax_tm_button">
<a id="send_message" href="#">Send Message</a>
</div>
</form>
PHP:
<?php
// Put contacting email here
$php_main_email = "[email protected]";
//Fetching Values from URL
$php_name = $_POST['ajax_name'];
$php_phone = $_POST["phone"];
$php_email = $_POST['ajax_email'];
$php_address = $_POST["address"];
$php_help = $_POST["help"];
$php_message = $_POST['ajax_message'];
//Sanitizing email
$php_email = filter_var($php_email, FILTER_SANITIZE_EMAIL);
//After sanitization Validation is performed
if (filter_var($php_email, FILTER_VALIDATE_EMAIL)) {
$php_subject = "FORM SUBMITTAL";
// To send HTML mail, the Content-type header must be set
$php_headers = 'MIME-Version: 1.0' . "rn";
$php_headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$php_headers .= 'From:' . $php_email. "rn"; // Sender's Email
$php_template = '<div style="padding:50px;"> ' .
'<strong style="color:#012345;">Name:</strong> ' . $php_name . '<br/>'
. '<strong style="color:#f00a77;">Phone:</strong> ' . $php_phone . '<br/>'
. '<strong style="color:#012345;">Email:</strong> ' . $php_email . '<br/>'
. '<strong style="color:#f00a77;">Address:</strong> ' . $php_address . '<br/>'
. '<strong style="color:#f00a77;">Help:</strong> ' . $php_help . '<br/>'
. '<strong style="color:#012345;">Message:</strong> ' . $php_message . '<br/><br/>'
. 'This is a Contact Confirmation mail.'
. '<br/>'
. 'We will contact you as soon as possible .</div>';
$php_sendmessage = "<div style="background-color:#f5f5f5; color:#333;">" . $php_template . "</div>";
// message lines should not exceed 70 characters (PHP rule), so wrap it
$php_sendmessage = wordwrap($php_sendmessage, 70);
// Send mail by PHP Mail Function
mail($php_main_email, $php_subject, $php_sendmessage, $php_headers);
echo "";
} else {
echo "<span class='contact_error'>* Invalid email *</span>";
}
?>