PHP Email Form Not Submitting [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Okay, so I've looked all around for this specific question but I wasn't able to find it, so I hope this isn't a repeat.
So I have set up a contacts form using my "/contacts.html" page linked to "html_form_send.php" located on my local host. Once the user presses "submit" this message comes up on the next page:
"We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
We are sorry, but there appears to be a problem with the form you submitted.
Please go back and fix these errors."
This message appears whether you fill out all fields or none of the fields, correctly, or incorrectly. Why?
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "xxxxxxxx.yyyyyyy#gmail.com";
$email_subject = "Quantum1Connect Contact Request";
function died($error) {
// your error code can go here
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // not required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // 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,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments 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($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);
?>
<!-- place your own success html below -->
Thanks for contacting me! I will respond within 24 hours of receiving your message!
<?php
}
die();
?>
<div id="content">
<div class="content_item">
<h2>Contact Me!</h2>
<p>Whether you have constructive criticism, advise, questions, or a request, this is the place to do it! </p>
<form name="htmlform" method="post" action="http://localhost/html_form_send.php">
<div style="width:170px; float:left;"><p><label for="first_name">First Name *</label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="first_name" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="last_name">Last Name </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="last_name" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="email">Email Address * </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="email" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="telephone">Phone Number </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="phone" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="comments">Message *</label></p></div>
<div style="width:430px; float:right;"><p><textarea class="contact textarea" rows="8" cols="50" name="message"></textarea></p></div>
<br style="clear:both;" />
<p style="padding: 10px 0 10px 0;">Please enter the answer to this simple math question (to prevent spam)</p>
<div style="width:170px; float:left;"><p>Maths Question: 9 + 3 = ?</p></div>
<div style="width:430px; float:right;">
<p><input type="text" name="user_answer" class="contact" /><input type="hidden" name="answer" value="4d76fe9775"/></p>
</div>
<div style="width:430px; float:right;">
<p style="padding-top: 15px"><form action="index.php"><input type="submit" value="Submit"></p>
</div>
</form>
</div><!--close content_item-->
Any help would be much appreciated, thank you so much!

Change:
<textarea class="contact textarea" rows="8" cols="50" name="message"></textarea>
to:
<textarea class="contact textarea" rows="8" cols="50" name="comments"></textarea>
You have set the name of the html textarea to message but you are testing for a textarea named comments in your php code.
Also as #Fred-ii pointed out, you are testing for telephone in the POST, but the value in html is phone
AND Remove - <form action="index.php"> that creates a SECOND form!
BTW, it should take you just half the effort of posting this question in SO, to run some quick debug echo/print_r/error_reporting statements and figure this out. If you are planning to get into more programming in the future, I highly recommend you work on your debugging skills, it is way more easier and efficient for such small problems. For the bigger ones, there is always SO :-)
Not being cynical, just an advice :) Best of luck!

Related

$error_message isn't showing when checkbox is empty

<form name="contactform" method="post" action="send_form_email.php">
<!--Name input-->
<input placeholder="Full Name *" type="text" name="name" maxlength="50">
<br />
<!--Email input-->
<input placeholder="Email Address *" type="email" name="email" maxlength="80">
<br />
<!--Phone number input (not required)-->
<input placeholder="Telephone Number" type="tel" name="telephone" maxlength="15">
<br />
<!--Company name input (not required)-->
<input placeholder="Company" type="text" name="company" maxlength="50">
<br />
<!--Comments & messege input-->
<textarea placeholder="Please include as much information as possible *" name="comments" maxlength="500" cols="25" rows="5"></textarea>
<br />
<!--Check for privacy policy-->
<label class="GDRP">
I consent to having this website store my submitted information so they can respond to my inquiry.
<input type="checkbox" name="GDRP">
</label>
<!--Submit button-->
<input type="submit" value="SUBMIT">
</form>
This is my HTML - I don't know how important it is to helping me find a solution but I figured, why not. I tried cleaning it up so you can get through with helping me as quick as possible. The only important fields are the 'name', 'email', 'comments' and the question at matter 'GDRP'.
<?php if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "email#adress.com";
$email_subject = "www.Adress.com - CONTACT FORM";
function died($error) {
// error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted: ";
echo $error."<br />";
echo "Please fix these errors.";
die();
}
// validation expected data exists
if(
!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['company']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments']) ||
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$company = $_POST['company']; // not required
$comments = $_POST['comments']; // required
$GDRP = $_POST['GDRP']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= '<br /><br /><font color="red">Full Name</font><br /><br />';
}
if(!preg_match($email_exp,$email_from)) {
$error_message .= '<font color="red">Email Address</font><br /><br />';
}
if(strlen($comments) < 2) {
$error_message .= '<font color="red">Comments</font><br /><br />';
}
if(!empty($GDRP)) {
$error_message .= '<font color="red">GDRP Agreement</font><br /><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($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);
?>
<body>
Thank you for contacting us. We will be in touch with you as soon as possible.
</body>
<?php
}
?>
My problem is that the checkbox ('GDRP') isn't showing $error_message when it's not filled in. In fact, none show when 'GDRP' is empty. If you fill 'GDRP' but leave the others [required fields] empty all of their $error_message except for 'GDRP' will show.
if(!empty($GDRP)) { // if not empty
$error_message .= '<font color="red">GDRP Agreement</font><br /><br />';
}
looks like you are checking that $GDPR isn't empty, this should be the other way around.
change if(!empty($GDRP)) { to if(empty($GDRP)) {.
Only checked checkboxes send and available in POST. So, looks like in the following lines your script finished and other errors not shown:
!isset($_POST['GDRP'])
) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

Properly coding Email Form with PHP? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
So, two problems:
1.) My email form is not working, on submit, it advises "web page can't be displayed".
2.) The email form, when properly coded, did not send an email.
I'm trying to get my email form to properly work. It was working, (however was not sending email) then I rearranged some things (added subject line in the form). Now, I can't seem to figure out what went wonky once I added a subject line. Any suggestions?
https://jsfiddle.net/ebxam743/1/
My PHP form is in the CSS section of JSFIDDLE.
Contact Form HTML
<div class="col-md-8">
<form name="contactform" method="post" action="send_form_email.php">
<div class="row contact-row">
<div class="col-md-6 contact-name">
<input type="text" name="first_name" placeholder="Name">
</div>
<div class="col-md-6 contact-email">
<input type="text" name="email" placeholder="E-mail*">
</div>
</div>
<input type="text" name="subject" placeholder="Subject*">
<textarea name="comments" placeholder="Message"></textarea>
<input type="submit" class="btn btn-lg btn-color btn-submit" value="Send Message">
</div>
</div>
</form>
<!-- end col -->
PHP (can't get it to format properly)...
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "you#yourdomain.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
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['first_name']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['subject']; // not required
$comments = $_POST['comments']; // 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,$first_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 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($first_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Subject: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);
?>
<!-- include your own success html here -->
<center><img src="img/rebelliouslogob.png"
Thank you for contacting us. We will be in touch with you very soon.</center>
<h1>Go Back</h1>
<?php
}
?>
Okay, so I found 2 errors.
First error
This line:
echo "Please go back and fix these errors.<br /><br />";
Should be changed to:
echo "Please go back and fix these errors.<br /><br />";
Because the quote symbol is breaking the string, so if you need to use the quote symbol inside a string you need to escape it by adding a backslash or create strings using single quotes.
Second error
You are referring to a variable called $subject that doesn't exist.
So instead of using a variable called $telephone which contains the subject data, change the name of it to $subject (you never use the variable $telephone, so it shouldn't affect you).
This line:
$telephone = $_POST['subject']; // not required
Should be changed to:
$subject = $_POST['subject']; // not required
EDIT: Tested the code on my server after the two changes I mentioned above, and I received an email as expected.

PHP contact form with multiple recipents [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a PHP-based contact-form, and it works fine, but I need it to send 3 or 4 different emails. How can I do that?
Here is my code:
<table class="table table-striped row-highlight table-condensed">
<thead>
<tr>
<th class="shortcut-base"><a>Base Key</a></th>
<th class="shortcut-binding"><a>Key Binding</a></th>
<th class="shortcut-cmd-id"><a>Command ID</a></th>
<th class="shortcut-cmd-name"><a>Command Name</a></th>
<th class="shortcut-orig"><a>Origin</a></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Contact us</title>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="style.css">
</head>
<body id="thankyou">
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "shovo654#gmail.com";
$email_subject = "Your email subject line";
function died($error) {
// your error code can go here
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_POST['comments']; // 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,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments 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($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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);
?>
<!-- include your own success html here -->
<div class="tahnkyou_page">
<div class="inner_thank">
<p>Thank you for contacting us. We will be in touch with you very soon.</p>
Home
</div>
</div>
</body>
</html>
<?php
}
?>
<div class="effect_form">
<form name="contactform" method="post" action="send_form_email.php">
<fieldset >
<div class='container fastname'>
<input type="text" name="first_name" maxlength="50" placeholder="Fast Name*">
</div>
<div class='container lastname'>
<input type="text" name="last_name" maxlength="50" placeholder="Last Name*">
</div>
<div class='container email'>
<input type="text" name="email" maxlength="80" placeholder="Email*">
</div>
<div class='container phone'>
<input type="text" name="telephone" maxlength="30" placeholder="Phone">
</div>
<div class='container message'>
<textarea name="comments" maxlength="1000" cols="25" rows="6" placeholder="Message*"></textarea>
</div>
<div class="effect_form_bottom">
<div class="eff_form_left">
<p class="phone">An AGE technician will contact you within 24 hours with a free no obligation quote</p>
<p class="lock">Your privacy is important, we do not provide information to third parties.</p>
</div>
<div class="eff_form_right">
<input type='submit' name='Submit' value='Get Free Quote' />
</div>
</div>
</fieldset>
</form>
</div>
So what needs to be done? I've tried, but I can't make it work.
To send an email to multiple recipients :
// multiple recipients
$email_to = 'aidan#example.com' . ', '; // note the comma
$email_to .= 'wez#example.com';
[...]
mail($email_to, $email_subject, $email_message, $headers);
Source: PHP.net

Adding working checkboxes to a contact form

I am trying to add checkboxes to my contact form. I have a working contact form that with 3 checkboxes. When I place the php code that I found on this page (send checkbox value in PHP form) then my checkboxes are no longer clickable BUT when the email sends all three checkboxes appear in the email. I think that there must be a simple fix somewhere but I have spent the whole live long day working on it and this is as far as I have been able to get.
How do I get the checkboxes clickable AND have the selected box be included in the email?
Here is my html
<section class="contact">
<form id="contact" action="html_form_send.php" method="post">
<fieldset title="About you">
<legend><span>About you</span></legend>
<label for="name">Name</label>
<input type="text" name="name" id="name" tabindex="10" class="txtinput" placeholder="Your name" required>
<label for="email">Email</label>
<input type="email" name="email" id="email" tabindex="20" class="txtinput" placeholder="valid email" required>
</fieldset>
<fieldset title="Your turn">
<legend><span>Your turn</span></legend>
<p>What, exactly then, are you after?</p>
<div>
<div class="tag">checkbox1</div>
<input type="checkbox" id="checkbox-1" class="regular-checkbox big-checkbox" value="Yes" />
<label for="salvation"></label>
</div>
<div>
<div class="tag">checkbox2</div>
<input type="checkbox" id="checkbox-2" class="regular-checkbox big-checkbox" value="Yes" />
<label for="question"></label>
</div>
<div>
<div class="tag">checkbox3</div>
<input type="checkbox" id="checkbox-3" class="regular-checkbox big-checkbox" value="Yes" />
<label for="other"></label>
</div>
<label for="comment" class="inline"></label>
<label for="discourse">Write your comments here</label>
<textarea id="discourse" name="discourse" tabindex="30" class="txtinput" rows="7" placeholder="This is where your thoughts go">
</textarea>
<section id="buttons">
<input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset">
<input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="40" value="Send away!">
<br style="clear:both;">
</section>
And here is my php
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "myemail#email.org";
$email_subject = "website feedback";
function died($error) {
// your error code can go here
echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['discourse'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$discourse = $_POST['discourse']; // not required $comments = $_POST['comments']; // 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,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($discourse) < 2) {
$error_message .= 'The Comments 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 .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "checkbox1: ".clean_string($checkbox-1)."\n";
$email_message .= "checkbox2: ".clean_string($checkbox-2)."\n";
$email_message .= "checkbox3: ".clean_string($checkbox-3)."\n";
$email_message .= "Comments: ".clean_string($discourse)."\n";
$checkbox1= $_POST['checkbox1'];
if ($checkbox1!= 'Yes') {
$checkbox1= 'No'; }
$checkbox2= $_POST['checkbox2'];
if ($checkbox2!= 'Yes') {
$checkbox2= 'No'; }
$checkbox3= $_POST['checkbox3'];
if ($checkbox3!= 'Yes') {
$checkbox3= 'No'; }
// 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);
?>
<?php
$checkbox = $_POST['value']
//Will return either "checkbox1" or "checkbox2" or "checkbox3".
?>
<!-- place your own success html below -->
<script language="javascript" type="text/javascript">
alert('Thank you for contacting us.');
window.location = 'feedbackform.html';
</script>
<?php
}
die();
?>
If the checkboxes aren't clickable then it is most likely that some other element(s) are sitting above them. Using your browser's developer tools is the quickest way to discover this. The PHP does not affect whether they are clickable or not.
If I were to guess it would be that their labels are sitting above them. (Note that empty elements like these should be avoided.)
The checkboxes (and other form elements) must have a name attribute in order to be submitted with the form.

PHP Email form not working properly

I am very new at php but even so, this does not make any sense to me:
I have an HTML page containing the php form as follows:
...
<article id="content"><div class="ic">Here comes the contact form!</div>
<div class="wrapper">
<h2>Contact form</h2>
<form method="post" id="ContactForm" name="myemailform" action="sendemail.php">
<div>
<div class="wrapper">
<span>Nume:</span>
<div class="bg"><input type="text" class="input" name="myname"></div>
</div>
<div class="wrapper">
<span>Adresa:</span>
<div class="bg"><input type="text" class="input" name="myadresa" ></div>
</div>
<div class="wrapper">
<span>Email:</span>
<div class="bg"><input type="text" class="input" name="myemail" ></div>
</div>
<div class="textarea_box">
<span>Mesaj:</span>
<div class="bg"><textarea name="textarea" cols="1" rows="1" name="mymesaj"></textarea></div>
</div>
<a href="#" class="button1" name='submit' value="submit" onclick='javascript: document.myemailform.binset=2; document.myemailform.submit();'>Send message</a>
</div>
</form>
</div>
</article>
And the action sendemail.php is as follows:
<?php
if(isset($_POST['submit'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "myreal_email#email.com";
$email_subject = "Message from contact form";
function died($error) {
// your error code can go here
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['myname']) ||
!isset($_POST['myadresa']) ||
!isset($_POST['myemail']) ||
!isset($_POST['mymesaj'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['myname']; // required
$last_name = $_POST['myadresa']; // required
$email_from = $_POST['myemail']; // required
$comments = $_POST['mymesaj']; // 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,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments 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 .= "Name: ".clean_string($first_name)."\n";
$email_message .= "Adresa: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Mesaj efectiv: ".clean_string($comments)."\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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
Now, the problem is that I receive the email, the subject is ok, the sender email is ok, but the message is empty... no $email_message is received.
Why is this happening?
Any help would be appreciated.
Thank you
the problem is with your
<textarea name="textarea" cols="1" rows="1" name="mymesaj"></textarea>
there are two names with the textarea check it.
<textarea cols="1" rows="1" name="mymesaj"></textarea>
if you are usinh HTML 5 or higher version...use 'required' in the input tags...which will automatically validate the input data is present or not...
like this:
<input type="text" class="input" name="myname" required>
and for email validation give the input type as email...not text
like this:
<input type="email" class="input" name="myemail" required >
Also try ajax,jquery for further form validations..

Categories