Hi there.
I came to you for help before and was greatly helped with the last problem I had. Since I still don't really get PHP I've had to return. I adapted the code for use on a friend's website, but it's not working properly because the information from the checkboxes is not being picked up. Where did I go wrong?
<form method="post" action="contact-mailer.php">
<div>Name:<span class="ss-required-asterisk">*</span><br>
<input name="name" size="45" type="text"><br>
<br>
Email:<span class="ss-required-asterisk">*</span><br>
<input name="email" size="45" type="text"><br>
<br>
Phone:<span class="ss-required-asterisk">*</span><br>
<input name="Phone" size="45" type="text"><br>
<br>
<h3>Which Dynamic Heights Training service are you interested in?</h3>
<input name="services" value="121" type="checkbox"> One-to-one
professional coaching <br>
<input name="services" value="interview" type="checkbox"> Interview
and presentation skills <br>
<input name="services" value="confidence" type="checkbox">
Confidence
& motivation <br>
<input name="services" value="bespoke" type="checkbox"> Bespoke
training design and delivery <br>
<input name="services" value="consultancy" type="checkbox">
Consultancy
services <br>
<br>
<br>
How would you prefer to be contacted?<br>
<br>
<input name="contact" value="phone" type="radio"> Phone <input name="contact" value="email" type="radio"> Email </div>
<br>
<br>
Comments:<span class="ss-required-asterisk">*</span><br>
<br>
<textarea rows="14" name="message" cols="45"> </textarea> <br>
<br>
<input value="Send" name="submit" type="submit"></form>
<?php
function spamcheck($field) {
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);
//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL)) {
return TRUE;
} else {
return FALSE;
}
}
$services = '';
if (isset($_POST['121']) &&$_POST['121'] == 'One-to-one_professional_coaching') {
$services .= "One-to-one professional coaching: checked\n";
} else {
$services .= "One-to-one professional coaching: unchecked\n";
}
if (isset($_POST['interview']) && $_POST['interview'] == 'Interview_and_presentation skills') {
$services .= "Interview and presentation skills: checked\n";
} else {
$services .= "Interview and presentation skills: unchecked\n";
}
if (isset($_POST['confidence']) && $_POST['confidence'] == 'Confidence_&_motivation') {
$services .= "Confidence & motivation: checked\n";
} else {
$services .= "Confidence & motivation: unchecked\n";
}
if (isset($_POST['bespoke']) && $_POST['bespoke'] == 'Bespoke_training_design_and_delivery') {
$services .= "Bespoke training design and delivery: checked\n";
} else {
$services .= "Bespoke training design and delivery: unchecked\n";
}
if (isset($_POST['consultancy']) && $_POST['consultancy'] == 'Consultancy_services') {
$services .= "Consultancy services: checked\n";
} else {
$services .= "Consultancy services: unchecked\n";
}
$contact = 'contact: ';
if (isset($_POST['contact'])) {
if ($_POST['contact'] == 'phone') {
$contact .= "Phone\n";
} else if ($_POST['contact'] == 'email') {
$contact .= "Email\n";
}
} else {
$contact .= "Not Answered\n";
}
if (isset($_REQUEST['email'])) {
//if "email" is filled out, proceed
//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST['email']);
if ($mailcheck==FALSE) {
echo "Invalid input";
} else {
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = '
Name: '. $_REQUEST['name'] .'
Email: '. $_REQUEST['email'] .'
Message: '. $_REQUEST['message'] .'
Services:
'. $services .'
'. $contact .'
Message received on: '. date('m/d/y h:i a');
$to = "info@company.org.uk";
$header = "From: info@company.org.uk" . PHP_EOL;
$header .= "Reply to: $email" . PHP_EOL;
if( mail($to, "Subject: $subject", $message, $header ) ) {
echo "<br /> Message sent successfully. ";
echo "<br /><br />Thank you for your enquiry. I'll get back to you as soon as possible.";
} else {
echo "Oh dear, there seems to have been a mistake. Please try again.";
}
}
} else {
//if "email" is not filled out, display the form
echo "<form method='post' action='contact-mailer.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
The info about how to be contacted is arriving okay, it's the services that are being read as unchecked. I just need to know what I'm getting wrong there to make it work properly. Thanks in advance.