Contact form Not Working Keeps Giving Me Array - php

So I have this contact script which works great in firefox but whenever anyone tries it in ie 7 or 8 the plan always returns array and for the life of me I cant figure out what I did wrong. Any help would be greatly appreciated.
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$cname = $_POST['cname'];
$address1 = $_POST['address'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$plan = $_POST['plan'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($cname) == '') {
echo '<div class="error_message">Attention! Please enter your Company Name.</div>';
exit();
}
if(trim($address1) == '') {
echo '<div class="error_message">Attention! Please enter your Address.</div>';
exit();
}
if(trim($city) == '') {
echo '<div class="error_message">Attention! Please enter your city.</div>';
exit();
}
if(trim($state) == '') {
echo '<div class="error_message">Attention! Please enter your state.</div>';
exit();
}
if(trim($zip) == '') {
echo '<div class="error_message">Attention! Please enter your zip code.</div>';
exit();
}
else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "email#email.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Veterans Career Fair: You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name from $cname, they wish to sign up for the $plan Plan. Their additional information is as follows:\r\n\n";
$e_reply = "Contact $name via email, $email or via phone $phone. \r\n\n";
$e_mail = "Address of $name is: $address1 $address2, $city, $state $zip";
$msg = $e_body . $e_reply . $e_mail;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "<p>You should hear from us in 48 hours</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
The Html
<form method="post" action="bin/sendme.php" name="contactform" id="contactform">
<label>Full Name</label>
<input name="name" type="text" id="name" size="30" value="" /><br />
<label>Email</label>
<input name="email" type="text" id="email" size="30" value="" /><br />
<label>Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" /><br />
<label>Company Name</label>
<input name="cname" type="text" id="cname" size="30" value="" /><br />
<label>Address 1</label>
<input name="address" type="text" id="address" size="30" value="" /><br />
<label>Address 2</label>
<input name="address2" type="text" id="address2" size="30" value="" /><br />
<label>City</label>
<input name="city" type="text" id="city" size="30" value="" /><br />
<label>State</label>
<input name="state" type="text" id="state" size="30" value="" /><br />
<label>Zip Code</label>
<input name="zip" type="text" id="zip" size="30" value="" /><br />
<label>Plan</label>
<select name="plan" type="text" id="plan">
<option value="Platinum">Platinum Sponsorship</option>
<option value="Gold">Gold Sponsorship</option>
<option value="Silver">Silver Sponsorship</option>
<option value="Survey">Survey Sponsorship</option>
<option value="Marquee">Marquee Sponsorship</option>
</select>
<label>3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="REGISTER NOW" />
</form>
The Jquery
jQuery(document).ready(function(){
$('#contactform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.after('<img src="assets/ajax-loader.gif" class="loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
cname: $('#cname').val(),
address: $('#address').val(),
city: $('#city').val(),
state: $('#state').val(),
zip: $('#zip').val(),
plan: $('#plan').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
$('#contactform #submit').attr('disabled','');
if(data.match('success') != null) $('#contactform').slideUp('slow');
}
);
});
return false;
});

<select name="plan" type="text" id="plan">
should be
<select name="plan" id="plan">

The html select element does not have an attribute type so perhaps that's confusing IE

Related

Change email address based on drop-down selection

I have a contact form with the following fields:
Name
Email
Number
Department
Message
"Department" is a drop down selection with the seven following options
Audio Engineering
Graphic Design
Music Production
Photography
Videography
Web Development
Other
I have been trying to set it up in such a way where the email address that the data is being sent to, changes based on the user's drop-down selection. For example, if the user selects Option 1, "Audio Engineering", the email will be sent to "audio#email.com". If the user selects Option 2, "Graphic Design", the email will be sent to "graphics#email.com" and so on, upon submission of the form. However, my current code returns an error.
This is my HTML.
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset id="contact_form">
<label for="name">
<input type="text" name="name" id="name" placeholder="ENTER YOUR NAME">
</label>
<label for="email">
<input type="email" name="email" id="email" placeholder="ENTER YOUR EMAIL">
</label>
<label for="phone">
<input type="text" name="phone" id="phone" placeholder="PHONE NUMBER">
</label>
<label for="department">
<select name="department" id="department" class="cs-select cs-skin-border" required>
<option value="" disabled selected>DEPARTMENT</option>
<option value="audio">Audio Engineering</option>
<option value="graphics">Graphic Design</option>
<option value="music">Music Production</option>
<option value="photography">Photography</option>
<option value="videography">Videography</option>
<option value="development">Web Development</option>
<option value="other">Other</option>
</select>
</label>
<label for="comments">
<textarea name="comments" id="comments" placeholder="ENTER YOUR MESSAGE"></textarea>
</label>
<input type="submit" class="submit btn btn-default btn-black" id="submit" value="Submit">
</fieldset>
</form>
This is the snippet of my PHP where I use if statements to change emails based on selection.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$dept = $_POST['department'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Please enter your name. Don\'t be shy!</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Please enter your email address, so we can get back to you!</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Invalid e-mail address, try again!</div>';
exit();
} else if(trim($comments) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">You forgot to enter your message!</div>';
exit();
}
if($dept == "audio") {
$address = "audio#email.com";
} else if ($dept == "graphics") {
$address = "graphics#email.com";
} else if ($dept == "music") {
$address = "music#email.com";
} else if ($dept == "photography") {
$address = "photography#email.com";
} else if ($dept == "videography") {
$address = "videography#email.com";
} else if ($dept == "development") {
$address = "development#email.com";
} else if ($dept == "other") {
$address = "admin#email.com";
}
if(mail($address, $received_subject, $message, $header)) {
// Email has sent successfully, echo a success page.
echo "<h2>Email Sent Successfully.</h2>";
echo "<p>Thank you <strong>$name</strong>, your message has been sent to us.</p>";
echo "<p>We will get back to you within 24 hours!</p>";
} else {
echo '<h2>ERROR!</h2>';
}
?>
This unfortunately returns "ERROR!" and i'm not sure why.
I would also like to return an error message if no selection is made.
Passed param to mail function.
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$dept = $_POST['department'];
$comments = $_POST['comments'];
if(trim($name) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Please enter your name. Don\'t be shy!</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Please enter your email address, so we can get back to you!</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">Invalid e-mail address, try again!</div>';
exit();
} else if(trim($comments) == '') {
echo '<div class="error_message" style="color: #de493e; font-weight: 700;">You forgot to enter your message!</div>';
exit();
}
if($dept == "audio") {
$address = "audio#email.com";
} else if ($dept == "graphics") {
$address = "graphics#email.com";
} else if ($dept == "music") {
$address = "music#email.com";
} else if ($dept == "photography") {
$address = "photography#email.com";
} else if ($dept == "videography") {
$address = "videography#email.com";
} else if ($dept == "development") {
$address = "development#email.com";
} else if ($dept == "other") {
$address = "admin#email.com";
}
$message = "First line of text\nSecond line of text";
$received_subject = "My subject";
if(mail($address, $received_subject, $message)) {
// Email has sent successfully, echo a success page.
echo "<h2>Email Sent Successfully.</h2>";
echo "<p>Thank you <strong>$name</strong>, your message has been sent to us.</p>";
echo "<p>We will get back to you within 24 hours!</p>";
} else {
echo '<h2>ERROR!</h2>';
}

Captcha Value is not reading while form submission

I came across a problem with PHP form submission. I'm not able to read the captcha filed value in form submission. Here is the code
HTML
<div class="container">
<h2 class="centertitle">Contact Us</h2>
<div id="message"></div>
<form method="post" action="php/contact.php" name="contactform" id="contactform">
<div class="row">
<div class="col-sm-3">
<input type="text" name="name" placeholder="Name" id="name" class="form-control" />
</div>
<div class="col-sm-3">
<input type="text" name="email" placeholder="Email" id="email" class="form-control" />
</div>
<div class="col-sm-3">
<input type="text" name="phone" placeholder="Phone" id="phone" class="form-control" />
</div>
<div class="col-sm-3">
<div id="captcha">
<input type="text" name="verify" id="verify" class="form-control" placeholder="Enter Captcha" />
<img src="php/image.php" alt="well, this is out capcha image" class="captcha" />
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 text-center">
<input type="submit" name="send" value="Submit" id="submit" class="sbtn" />
</div>
</div>
</form>
</div><!-- /.container -->
Js Validation
$(document).ready(function() {
//Form Validation
$('#contactform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
//.after('<img src="images/ajax-loader.gif" class="loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
subject: $('#subject').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#contactform').slideUp('slow');
}
);
});
return false;
});
});
Contact.PHP
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have entered an invalid e-mail address. Please try again.</div>';
exit();
}
if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please Verify CAPTCHA.</div>';
exit();
}else if(trim($verify) === $_SESSION["security_number"]) {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "contact#sreejesh.in";
$e_subject = 'Form Submission.';
$e_body = "You have a new Form Submission." . PHP_EOL . PHP_EOL;
$e_content = "Name: $name,\rPhone: $phone,\rEmail: $email" . PHP_EOL . PHP_EOL;
$e_reply = "";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h4>Email Sent Successfully.</h4>";
echo "<p>Thank you <strong>$name</strong>, for your interest We will contact you shortly.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
For some reason I'm NOT getting value of $captcha
It returns an error says**
Currently the form get submitted without validation.
For Captcha image I use this code -
Captcha Code(IMAGE.PHP)
<?php
session_start();
$img=imagecreatefromjpeg("texture.jpg");
$security_number = empty($_SESSION['security_number']) ? 'error' : $_SESSION['security_number'];
$image_text=$security_number;
$red=rand(100,255);
$green=rand(100,255);
$blue=rand(100,255);
$text_color=imagecolorallocate($img,255-$red,255-$green,255-$blue);
$text=imagettftext($img,16,rand(-10,10),rand(10,30),rand(25,35),$text_color,"fonts/courbd.ttf",$image_text);
header("Content-type:image/jpeg");
header("Content-Disposition:inline ; filename=secure.jpg");
imagejpeg($img);
?>
I'm a beginer in PHP & I'm sitting with this code for the last few hours. PLs help.
Here is a live URL - http://aisther.com/projects/sri/
Do not echo your session variable is it being created by your image.php script and exposing it to the user makes the captcha pointless.
HTML
<form action="contact.php" method="post">
<div id="captcha">
<img src="php/image.php" alt="well, this is out capcha image" class="captcha" />
<input type="text" name="verify" id="verify" class="form-control" placeholder="Enter Captcha" />
</div>
</form>
PHP
session_start();
if($_POST'verify'] == $_SESSION["security_number"]) {
echo 'captcha matched';
} else {
echo 'bad captcha';
}
If you want to use $_POST to read the form data, the form tag needs to look like
<form action='contact.php' method='post'>
Issue solved after adding session_start(); in contact.php
final code(contact.php)
<?php
session_start();
*********************************************************
$verify = $_POST['verify'];
$captcha = $_SESSION["security_number"];
*********************************************************
if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please Verify CAPTCHA.</div>';
exit();
}else if(trim($verify) != trim($captcha)) {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
*********************************************************
?>

Issues with php verification script

I'm not very familiar with PHP. In the past I have been able to read and fix small problems using PHP but this one is giving me quite lot of trouble.
I have a form with two entry boxes, one for email and one for message.
Now, Im trying to add another box to the form to verify human access for anti-spam purposes.
This is the code which I can't make the verification process go through.
//create ramdom numbers
<?php
$num1 = rand(0,9);
$num2 = rand(0,9);
?>
<?php
$error = '';
$email = '';
$comments = '';
$verify = '';
if(isset($_POST['contactus'])) {
$email = $_POST['email'];
$comments = $_POST['comments'];
$app = $_SERVER["REQUEST_URI"];;
if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
//This is where Im having problem. From this point the form doesn't go on.
if(trim($verify) == '') {
error( '<div class="error_message">Attention! Please enter the verification number.</div>');
} else if(trim($verify) != $verify_result) {
error( '<div class="error_message">Attention! The number you entered is incorrect.</div>');
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "info#myaddress.com";
$e_subject = 'You\'ve been contacted from an app web page ' . $name . '.';
$e_body = "You have been contacted using the app comments box on the above app web page, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
$e_reply = "$name $email";
$msg = $e_body . $e_content . $e_reply;
mail($address, $e_subject, $msg, $app, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
// Email has sent successfully, echo a success page.
echo "<div id='success_page_apps'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you, your message has been submitted to us.</p>";
echo "</div>";
echo '<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">';
}
}
if(!isset($_POST['contactus']) || $error != '') {
<?php echo $error; ?>
<fieldset id="contact_apps">
<form method="post" action="#ContactForm">
<label for="email" accesskey="E"><span class="required"></span> Email</label>
<input name="email" type="text" id="email" size="33" value="<?php echo$email;?>"/>
<textarea name="comments" cols="50" rows="15" id="comments"><?php echo$comments;?></textarea>
//This is the 'Are you human?' message
<p><span class="required">*</span> Are you human?</p>
<label class="numbersq" for='verify' accesskey='V'><?php echo $num1; ?> + <?php echo $num2; ?> =</label>
<input class="numbersa" name="verify" type="text" id="verify" size="4" value=""/>
<input name="verify_result" type="hidden" size="4" value="<?php echo $num1+$num2; ?>" /><br />
<input name="contactus" type="submit" class="send" id="contactus" >
</form>
</fieldset>
}
?>
Please note the 'Are you human' message and the conditionals I have in the script which is where I think I'm doing something wrong.
You've forgotten to pull the verify values from the form ... and you have a few other simple errors in there too which I've addressed.
//create ramdom numbers
<?php
$num1 = rand(0,9);
$num2 = rand(0,9);
?>
<?php
$error = '';
$email = '';
$comments = '';
$verify = '';
if(isset($_POST['contactus'])) {
$email = $_POST['email'];
$comments = $_POST['comments'];
$app = $_SERVER["REQUEST_URI"];;
if(trim($comments) == '') {
$error = '<div class="error_message">Attention! Please enter your message.
</div>';
} else if(trim($email) == '') {
$error = '<div class="error_message">Attention! Please enter a valid email address.
</div>';
} else if(!isEmail($email)) {
$error = '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
}
//This is where Im having problem. From this point the form doesn't go on.
$verify_result= $_POST['verify_result'];
$verify = $_POST["verify"];
if(trim($verify) == '') {
$error = '<div class="error_message">Attention! Please enter the verification number.</div>';
} else if(trim($verify) != $verify_result) {
$error = '<div class="error_message">Attention! The number you entered is incorrect.</div>';
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
$address = "info#myaddress.com";
$e_subject = 'You\'ve been contacted from an app web page ' . $name . '.';
$e_body = "You have been contacted using the app comments box on the above app web page, their additional message is as follows.\r\n\n";
$e_content = "\"$comments\"\r\n\n";
$e_reply = "$name $email";
$msg = $e_body . $e_content . $e_reply;
// mail($address, $e_subject, $msg, $app, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n");
// Email has sent successfully, echo a success page.
echo "<div id='success_page_apps'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you, your message has been submitted to us.</p>";
echo "</div>";
echo '<input type="button" value="Send Another" onClick="history.go(-1); return (true); ">';
}
}
if(!isset($_POST['contactus']) || $error != '') {
echo $error; ?>
<fieldset id="contact_apps">
<form method="post" action="#ContactForm">
<label for="email" accesskey="E"><span class="required"></span> Email</label>
<input name="email" type="text" id="email" size="33" value="<?php echo$email;?>"/>
<textarea name="comments" cols="50" rows="15" id="comments"><?php echo$comments;?></textarea>
//This is the 'Are you human?' message
<p><span class="required">*</span> Are you human?</p>
<label class="numbersq" for='verify' accesskey='V'><?php echo $num1; ?> + <?php echo $num2; ?> =</label>
<input class="numbersa" name="verify" type="text" id="verify" size="4" value=""/>
<input name="verify_result" type="hidden" size="4" value="<?php echo $num1+$num2; ?>" /><br />
<input name="contactus" type="submit" class="send" id="contactus" >
</form>
</fieldset>
<?PHP
}
?>

Get multiple values of checkbox in PHP

I need help with this if any can show me, that would be so great and helpful.
I am trying to get more then one value show up through a checkbox, with this information in PHP has been sent to an email. I can get anyone on the selected list work individually when applied
This is my PHP & HTML code, it all works fine, it's just the program will only send one of the selected list, even if I select more then one.
$ch1, $ch2, $ch3, $ch4 ,$ch5
PHP
<?php
if(isset($_POST['email'])) {
$email_to = "";
$email_subject = "";
function died($error) {
// Error Code
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['firstname']) ||
!isset($_POST['lastname']) ||
!isset($_POST['checkboxes']) ||
!isset($_POST['gender']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['telephone']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$firstname = $_POST['firstname']; // required
$lastname = $_POST['lastname']; // required
$ch1 = 'unchecked'; // required
$ch2 = 'unchecked'; // required
$ch3 = 'unchecked'; // required
$ch4 = 'unchecked'; // required
$ch5 = 'unchecked'; // required
$male_status = 'unchecked'; // required
$female_status = 'unchecked'; // required
$email_from = $_POST['email']; // required
$subject = $_POST['subject']; // required
$telephone = $_POST['telephone']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$firstname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$lastname)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$subject)) {
$error_message .= 'The Subject you entered does not appear to be valid.<br />';
}
if (isset($_POST['checkboxes'])) {
$selected_checkboxes = $_POST['checkboxes'];
if (isset($_POST['ch1'])) {
$ch1 = $_POST['checkboxes'];
if ($ch1 == 'googlechrome') {
$ch1 = 'checked';
}
}
if (isset($_POST['ch2'])) {
$ch2 = $_POST['checkboxes'];
if ($ch2 == 'firefox') {
$ch2 = 'checked';
}
}
if (isset($_POST['ch3'])) {
$ch3 = $_POST['checkboxes'];
if ($ch3 == 'safari') {
$ch3 = 'checked';
}
}
if (isset($_POST['ch4'])) {
$ch4 = $_POST['checkboxes'];
if ($ch4 == 'internetexplorer') {
$ch4 = 'checked';
}
}
if (isset($_POST['ch5'])) {
$ch5 = $_POST['checkboxes'];
if ($ch5 == 'opera') {
$ch5 = 'checked';
}
}
}
if (isset($_POST['gender'])) {
$selected_radio = $_POST['gender'];
if ($selected_radio == 'male') {
$male_status = 'checked';
}
else if ($selected_radio == 'female') {
$female_status = 'checked';
}
}
if(strlen($message) < 2) {
$error_message .= 'The Message you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($firstname)."\n";
$email_message .= "Last Name: ".clean_string($lastname)."\n";
$email_message .= "Gender: ".clean_string($selected_radio)."\n";
$email_message .= "Telephone: ".clean_string($telephone).
"\n";
$email_message .= "Email: ".clean_string($email_from).
"\n";
$email_message .= "Subject: ".clean_string($subject).
"\n";
$email_message .= "Browsers Used: ".clean_string($selected_checkboxes)."\n";
$email_message .= "Message: ".clean_string($message).
"\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
HTML
<form id="contact" name="contact" action="contact.php" method="post">
<p>
<label for="firstname">First Name *<br>
</label>
<input type="text" name="firstname" maxlength="50" size="30" id="firstname" placeholder="First Name" required autofocus>
<label for="lastname"><br>
<br>
Last Name *<br>
</label>
<input type="text" name="lastname" maxlength="50" size="30" id="lastname" placeholder="Last Name" required>
<label for="email"><br>
<br>
Email Address *<br>
</label>
<input type="text" name="email" maxlength="80" size="30" id="email" placeholder="example#domain.com" required>
<label for="telephone"><br>
<br>
Telephone <br>
</label>
<input type="text" name="telephone" maxlength="30" size="30" id="subject" placeholder="Phone Number" required>
<br>
<br>
<label for="subject">Subject *</label>
<br>
<input type="text" name="subject" maxlength="30" size="30" id="subject" placeholder="Hello" required>
<br>
<br>
<Input type = "Radio" Name ="gender" value= "Male">Male
<Input type = "Radio" Name ="gender" value= "Female" >Female
<br>
</p>
<p>"What browser are you using, to view this website"<br>
<Input type = "Checkbox" Name ="checkboxes" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes" value="Opera" >Opera
<br>
<br>
Message *<br>
</label>
<textarea name="message" maxlength="1000" cols="90" rows="6" id="message" placeholder="Type message here" required></textarea>
<br>
<input type="submit" value="Submit">
</p>
</form>
<Input type = "Checkbox" Name ="checkboxes[]" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes[]" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes[]" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes[]" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes[]" value="Opera" >Opera
The correct way to do this is to give your checkboxes different names.
<input type="checkbox" name="chrome" value="Google Chrome" />Chrome
<input type="checkbox" name="firefox" value="Firefox" />Firefox
<input type="checkbox" name="safari" value="Safari" />Safari
<input type="checkbox" name="ie" value="Internet Explorer" />IE
<input type="checkbox" name="opera" value="Opera" />Opera
Just FYI, the <label> tag is pretty useful here, so the text will be "tied" to the box when you click or hover.
<label for='cb1'>
<input id='cb1' type = "Checkbox" name ="chrome" value="Google Chrome" />Chrome
</label>
You can style it like
label:hover { background:orange; }
This also works for radio buttons.
Also, it's a good idea to avoid mixing up uppercase and lowercase of your attributes (the type, name, etc. are called attributes). You want everything in lowercase whenever possible.
If you changes the name parameter in your html to checkboxes[]:
<Input type = "Checkbox" Name ="checkboxes[]" value="Google Chrome">Google Chrome
<Input type = "Checkbox" Name ="checkboxes[]" value="Firefox">Firefox
<Input type = "Checkbox" Name ="checkboxes[]" value="Safari">Safari
<Input type = "Checkbox" Name ="checkboxes[]" value="Internet Explorer" >Internet Explorer
<Input type = "Checkbox" Name ="checkboxes[]" value="Opera" >Opera
Then $_POST['checkboxes'] will contain an array of the selected values.
Note that it won't return anything for the checkboxes that weren't selected, so you'll need to keep track of all values to compare to what was selected.

Form contents not showing in email

This is a followup to a question I posted yesterday. I thought everything was working fine, but today, I am not getting any results in the email from the drop down field.
Here is the form code in question:
<form method="post" action="contact.php" name="contactform" id="contactform">
<fieldset>
<legend>Please fill in the following form to contact us</legend>
<label for="name"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="30" value="" />
<br />
<label for="company">Company</label>
<input name="company" type="text" id="company" size="30" value="" />
<br />
<label for="email"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="30" value="" />
<br />
<label for="phone"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="30" value="" />
<br />
<label for="purpose"><span class="required">*</span> Purpose</label>
<select name="purpose" id="purpose" style="width: 300px; height:35px;">
<option value="none selected" selected="selected">-- Select One --</option>
<option value="I am interested in your services">I am interested in your services!</option>
<option value="I am interested in a partnership">I am interested in a partnership!</option>
<option value="I am interested in a job">I am interested in a job!</option>
</select>
<br />
<label for=comments><span class="required">*</span> Comments</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>
<p><span class="required">*</span> Please help us control spam.</p>
<label for=verify accesskey=V> 3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />
<input type="submit" class="submit" id="submit" value="Submit" />
</fieldset>
</form>
It is then processed in PHP and should output the selected option to an email, however the Reason for Contact line always comes through with nothing in it.
Here is the PHP code:
<?php
if(!$_POST) exit;
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$purpose = $_POST['purpose'];
$comments = $_POST['comments'];
$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(trim($phone) == '') {
echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Attention! Please enter your message.</div>';
exit();
} else if(trim($verify) == '') {
echo '<div class="error_message">Attention! Please enter the verification number.</div>';
exit();
} else if(trim($verify) != '4') {
echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
exit();
}
if($error == '') {
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
$address = "myname#email.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'You\'ve been contacted by ' . $name . '.';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name.\r\n\n";
$e_company = "Company: $company\r\n\n";
$e_content = "Comments: \"$comments\"\r\n\n";
$e_purpose = "Reason for contact: $purpose\r\n\n";
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = $e_body . $e_content . $e_company . $e_purpose . $e_reply;
if(mail($address, $e_subject, $msg, "From: $email\r\nReply-To: $email\r\nReturn-Path: $email\r\n")) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
}
function isEmail($email) { // Email address verification, do not edit.
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
?>
Any assistance would be greatly appreciated. Thanks!
It really looks like it should work, so I'd verify the dumbly obvious stuff: is your <select> tag contained within the <form> tag? Is 'purpose' mis-typed somewhere (it all looks good here, from what I can see)?
What happens if you do print_r($_POST)?
What happens if you do var_dump($purpose) after it is initialized?
Did you check if the server is able to send emails?
Check if sendmail actually works on your server before trying to debug your code (that seems to be good).

Categories