HTML form doesnt work [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
complete newbie in this.
a guy sent me a code for a contact form. the form looks nice, however it is not functioning(pressing submit does nothing). I guessed that the relevant section from the whole code is the one I pasted below.
how do I turn this into a working form?
<!-- Content -->
<div id="main">
<div class="wrapper cf">
<div class="content contact-block cf">
<h2><i>Contact</i> Us</h2>
<div class="sidebar-form cf">
<div class="row"><input id="firstname" type="text" name="fname" value="" placeholder="FIRST NAME" /></div>
<div class="row"><input id="lastname" type="text" name="lname" value="" placeholder="LAST NAME" /></div>
<div class="row"><input id="email" type="text" name="email" value="" placeholder="EMAIL ADDRESS" /></div>
<div class="row"><input id="order" type="text" name="order" value="" placeholder="ORDER NUMBER" /></div>
<div class="row">
<select id="subject" name="subject">
<option value="0" selected="selected">SUBJECT</option>
<option value="1">Received Error Message</option>
<option value="2">Login Issues</option>
<option value="3">Billing Questions</option>
<option value="4">Membership Questions</option>
<option value="5">Privacy Issues</option>
<option value="6">Report Abuse</option>
<option value="7">Legal Department</option>
<option value="8">Other</option>
<option value="9">How Do I Access Reports I've Run</option>
<option value="10">Account Cancellation</option>
</select>
</div>
<div class="row"><textarea name="comments" cols="" rows="" placeholder="COMMENTS OR QUESTIONS"></textarea></div>
<div class="row"><input type="submit" name="submit" value="Submit" /></div>
</div>
</div>
</div>
</div>
<!-- // Content -->
This is the contactengine.php file
<?php
$EmailFrom = "mymail#gmail.com";
$EmailTo = "mymail#gmail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$fname = Trim(stripslashes($_POST['fname']));
$lname = Trim(stripslashes($_POST['lname']));
$Email = Trim(stripslashes($_POST['Email']));
$order = Trim(stripslashes($_POST['order']));
$subject = Trim(stripslashes($_POST['subject']));
$comments = Trim(stripslashes($_POST['comments']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $fname;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $lname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "order: ";
$Body .= $order;
$Body .= "\n";
$Body .= "subject: ";
$Body .= $subject;
$Body .= "\n";
$Body .= "comments: ";
$Body .= $comments;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Add this code inside form tag.
<!-- Content -->
<form method="post" action="">
<div id="main">
<div class="wrapper cf">
<div class="content contact-block cf">
<h2><i>Contact</i> Us</h2>
<div class="sidebar-form cf">
<div class="row"><input id="firstname" type="text" name="fname" value="" placeholder="FIRST NAME" /></div>
<div class="row"><input id="lastname" type="text" name="lname" value="" placeholder="LAST NAME" /></div>
<div class="row"><input id="email" type="text" name="email" value="" placeholder="EMAIL ADDRESS" /></div>
<div class="row"><input id="order" type="text" name="order" value="" placeholder="ORDER NUMBER" /></div>
<div class="row">
<select id="subject" name="subject">
<option value="0" selected="selected">SUBJECT</option>
<option value="1">Received Error Message</option>
<option value="2">Login Issues</option>
<option value="3">Billing Questions</option>
<option value="4">Membership Questions</option>
<option value="5">Privacy Issues</option>
<option value="6">Report Abuse</option>
<option value="7">Legal Department</option>
<option value="8">Other</option>
<option value="9">How Do I Access Reports I've Run</option>
<option value="10">Account Cancellation</option>
</select>
</div>
<div class="row"><textarea name="comments" cols="" rows="" placeholder="COMMENTS OR QUESTIONS"></textarea></div>
<div class="row"><input type="submit" name="submit" value="Submit" /></div>
</div>
</div>
</div>
</div>
<!-- // Content -->
</form>

Related

creating mail form in html and php

I am currently having issues getting my php and html working correctly. When I click 'submit' It goes to an error page saying it cannot find webpage I requested (www.website.com/contact-form-handler.php).
Here is the PHP and HTML
HTML:
<html>
<head></head
<body>
<div>
<form action="contact-form-handler.php" method="post" name="contact_form">
<div class="col-md-6 col-sm-6 form-group">
<input name="name" type="text" class="form-control" id="nameInput" placeholder="Name" required>
<input name="email" type="email" class="form-control" id="emailInput" placeholder="Email" required>
<input name="phone" type="text" class="form-control" id="phoneInput" placeholder="Phone" required>
<input name="location" type="text" class="form-control" id="locationInput" placeholder="Event Location" required>
<select name="eventType" type="select" class="form-control" id="eventTypeInput">
<option selected>Type of Event</option>
<option value="1">Business</option>
<option value="2">Party</option>
<option value="3">Speech</option>
</select>
<select name="reference" type="select" class="form-control" id="referenceInput">
<option selected>How did you hear about us?</option>
<option value="1">Social Media</option>
<option value="2">Word of Mouth</option>
<option value="3">Google Search</option>
</select>
</div>
<div class="col-md-6 col-sm-6 form-group">
<textarea name="message" rows="7" class="form-control" id="messageInput" placeholder="Message"></textarea>
</div>
<div class="col-md-offset-4 col-md-4 col-sm-offset-3 col-sm-6 font3">
<input name="submit" type="submit" class="form-control" id="submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
PHP:
<?php
$errors = '';
$emails = 'myemail#myemail.com';//<-----Put Your email address here.
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['location']) ||
{
$errors .= "\n Error: Please fill out required fields";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$location = $_POST['location'];
$eventType = $_POST['eventType'];
$reference = $_POST['reference'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $emails;
$subject = "David Does Stuff Inquiry: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Phone: $phone \n Location of event: $location \n Type of Event: $eventType \n How did you hear about us: $reference \n Message \n $message";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $emails";
mail($to,$subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
See if your PHP file name is "contact-form-handler.php" or maybe you're getting the error coz' your PHP file might not be in the same directory.
Please check your form
<form action="contact-form-handler.php" method="post" name="contact_form">
your header location is incorrect, it should be
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.php');

Get PHP contact form to email last name and dropdowns menu selections

I have an HTML / PHP form built. It is working and submits successfully on the page stating the form has been submitted.
It emails me some information but I need to include Last Name and the options selected in two drop down menus Program and Start Term.
Any help appreciated. Thanks.
Here's the HTML:
<form class="form" role="form" method="POST" id="phpcontactform">
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:15px;">
<input class="form-control input-lg" name="name" id="name" type="text" placeholder="First Name" required>
</div>
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:0px;">
<input class="form-control input-lg" name="lname" id="lname" type="text" placeholder="Last Name" required>
</div>
<div class="form-group">
<input class="form-control input-lg" name="email" id="email" type="email" placeholder="Email" required>
</div>
<div class="form-group">
<input class="form-control input-lg" name="mobile" id="mobile" type="text" placeholder="Phone">
</div>
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:15px;">
<select class="form-control input-lg" id="program" name="program" type="text">
<option value="" selected="selected">Program</option>
<option value="1" >One Year MBA</option>
<option value="2" >Part-Time MBA</option>
</select>
</div>
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:0px;">
<select class="form-control input-lg" id="startterm" name="startterm" type="text">
<option value="" selected="selected">Start Term</option>
<option value="1" >Fall 2016</option>
<option value="2" >Spring 2017</option>
<option value="3" >Summer 2017</option>
<option value="4" >Fall 2017</option>
</select>
</div>
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:15px;">
Apply Now
</div>
<div class="form-group col-md-6 last" style="padding-left: 0px; padding-right:0px;">
<input type="submit" class="btn btn-warning btn-block btn-lg" value="Submit">
</div>
</form>
Then the PHP:
<?
$name = $_REQUEST["name"];
$lname = $_REQUEST["lname"];
$email = $_REQUEST["email"];
$mobile = $_REQUEST["mobile"];
$program = $_REQUEST["program"];
$startterm = $_REQUEST["startterm"];
//$msg = $_REQUEST["msg"];
$to = "XXXXX#gmail.com"; // <--- Change email ID here
if (isset($email) && isset($name)) {
$subject = "$name sent you a message";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
$msg = "From: $name <br /> Last Name: $lname <br/> Email: $email <br/>
Phone: $mobile <br /> Program: $program <br /> Start Term: $startterm";
//<br/>Message: $msg
$mail = mail($to, $subject, $msg, $headers);
if ($mail) {
echo 'success';
} else {
echo 'failed';
}
}
?>
Here is an example of collecting data from a select list:
<?php
$choices = array(
'foo' => 'big',
'bar' => 'fat',
'baz' => 'mamma'
);
if($_SERVER['REQUEST_METHOD'] == 'POST') {
$choice = isset($_POST['choice']) ? $_POST['choice'] : null;
$email = isset($_POST['email']) ? $_POST['email'] : null;
if(! array_key_exists($choice, $choices) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
throw new Exception ("Invalid Choice or email");
}
$message = sprintf("User with email: %s, selected: %s.", $email, $choices[$choice]);
echo $message;
die;
}
?>
<form method="POST">
Email:
<input type="text" name="email">
Choose:
<select name='choice'>
<?php foreach($choices as $k => $v) { ?>
<option value="<?php echo $k; ?>">
<?php echo $v ?>
</option>
<?php } ?>
</select>
<input type="submit">
</form>
first of all, change the html coding for the drop down menu as below
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:15px;">
<select class="form-control input-lg" id="program" name="program" type="text">
<option value="" selected="selected">Program</option>
<option value="OneYearMBA" >OneYearMBA</option>
<option value="Part-TimeMBA" >Part-TimeMBA</option>
</select>
</div>
<div class="form-group col-md-6" style="padding-left: 0px; padding-right:0px;">
<select class="form-control input-lg" id="startterm" name="startterm" type="text">
<option value="" selected="selected">Start Term</option>
<option value="Fall2016" >Fall2016</option>
<option value="Spring2017" >Spring2017</option>
<option value="Summer2017" >Summer2017</option>
<option value="Fall2017" >Fall2017</option>
</select>
</div>
I guess you want program and start term to be text values instead of numbers. Then it is not advised to leave spaces in the options(the value to be printed on page). Then one more thing in your html put action="phppage.php". then retrieve the values in your php page as $_POST['fieldname'].

Sending selected option value to email with php

I want the customer to pick different options from a dropdown, and then display the selected option in an email after they have submitted a form. It is supposed to send an email to me and the customer. Right now it's not sending the value from the select.
I have the following code:
<?php
if(isset($_POST['submit'])){
$to = "myemail#myemail.com"; // this is your Email address
$from = $_POST['email_address']; // this is the sender's Email address
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_street = $_POST['address_street'];
$phone = $_POST['phone_no'];
$quantity = $_POST['quantity'];
$select = $_POST['select'];
$subject = "Write the subject here";
$subject2 = "Write the subject here";
$message = "You have selected:" . "\n\n" . "" . $phone . $_POST['quantity'] . $_POST['select'] . $_POST['address_street'];
$message2 = "you have selected:" . "\n\n" . "" . $_POST['quantity'] . $_POST['select'] . $_POST['address_street'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Din mail er sendt " . $first_name . " " . $last_name . " " . ". Du har valgt følgende vinduer: " . $select;
}
?>
<form action="" method="POST">
<div class="row">
<div class="large-3 medium-6 small-12 columns">
<img class="windows" src="http://spejlblank.nu/wp-content/uploads/2016/03/SPEJLBLANK_INTERIOR_V036_ENKELTFAG.jpg" width="385" height="385" alt="">
<div class="dropdown-option">
<select id="select" name="select">
<option value="" selected>VÆLG POLERINGSTYPE</option>
<option value="30">INDVENDIG + UDVENDIG</option>
<option value="60">UDVENDIG</option>
<option value="90">INDVENDIG</option>
<option value="90">FORSATS (INKL. INDVENDIG + UDVENDIG)</option>
</select>
</div>
<div class="quantity-field">
<input type="number" name="quantity" min="0" max="100" placeholder="STK.">
</div>
</div>
<div class="row contact-form-pris">
<h3 style="text-transform: uppercase;">Indtast dine oplysninger og modtag dit uforpligtende tilbud!</h3>
<div class="large-6 small-12 columns">
<label for="first_name">Fornavn *</label>
<input class="" name="first_name" id="first_name" type="text" required/>
</div>
<div class="large-6 small-12 columns">
<label for="last_name">Efternavn *</label>
<input class="" name="last_name" id="last_name" type="text" required/>
</div>
<div class="large-12 columns">
<label for="address_street">Adresse *</label>
<input class="" name="address_street" id="address_street" type="text" required/>
</div>
<div class="large-6 small-12 columns">
<label for="email_address">Email *</label>
<input class="" name="email_address" id="email_address" type="email" required/>
</div>
<div class="large-6 small-12 columns">
<label for="mobile_no">Telefon *</label>
<input class="" name="mobile_no" id="mobile_no" type="tel" required/>
</div>
<div class="large-12 columns text-center">
<input type="submit" name="submit" value="MODTAG UFORPLIGTENDE TILBUD" class="submit-pris">
</div>
</div>
</form>
Try this in your drop down
<select id="select" name="select">
<option value="VÆLG POLERINGSTYPE" selected>VÆLG POLERINGSTYPE</option>
<option value="INDVENDIG + UDVENDIG">INDVENDIG + UDVENDIG</option>
<option value="UDVENDIG">UDVENDIG</option>
<option value="INDVENDIG">INDVENDIG</option>
<option value="FORSATS (INKL. INDVENDIG + UDVENDIG)">FORSATS (INKL. INDVENDIG + UDVENDIG)</option>
</select>
In your first option you were sending blank value and other values were numbers which you probably don't want to show to make email meaningful.
Change
<option value="" selected>VÆLG POLERINGSTYPE</option>
to
<option value="" >VÆLG POLERINGSTYPE</option>

How do I stop the Phantom Emails from my PHP code?

I'm currently using an html5 website with a contact form and a php action to receive contact emails. I've tried a few different codes in my php but non have stopped the blank emails from coming. I do have google analytics enables on my code but have blocked the crawler through robot.txt. Here is my code.
PHP CODE
<?php
foreach ($_GET as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));
$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
$to = "junior.8791#gmail.com";
$message = "Name: ".$name;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message .= "\n\nMessage: ".$messages;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";
} else {
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
?>
CONTACT FORM
<form action="email.php" method="post" id="form">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="e.g.'John Doe'" required="" />
</div>
<div class="6u">
<input type="email" class="email" name="email" id="email" placeholder="Email" required="" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="messages" id="messages" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message">
<input type="reset" class="button button-alt" value="Clear Form">

php form submitted, but no email received

I am attempting to send an email by filling out a contact form. Both my html form and php file are included below. Once I fill out the form, it notifies me that the email has been sent. However, I never receive an email; I cannot figure out what i am doing wrong.
This is my html form:
<div class="row" style="padding-top:27px">
<div class="large-6 column">
<form action="mail.php" method="POST" data-abide>
<div class="name-field">
<label>Your name*</label>
<input type="text" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
</div>
<div class="large-6 column">
<!-- <label> Message </label>
<textarea class="error" placeholder="Message..." id="info" class="message" name="message" cols="70" rows="60" size="90" requi></textarea><br>-->
<label> Message </label>
<textarea class="error" placeholder="Message..." ></textarea>
<small class="error">Invalid entry</small>
<div>
<input style="float:right;" type="submit" value="Submit">
<img style="visibility: hidden;">
</div>
</form>
This is my php file:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
UPDATED FILES:
HTML:
<div class="name-field">
<label>Your name*</label>
<input type="text" name="name" required pattern="[a-zA-Z]+">
<small class="error">Name is required and must be a string.</small>
</div>
<div class="email-field">
<label>Email*</label>
<input type="email" name="email" required>
<small class="error">An email address is required.</small>
</div>
<div>
<label> Subject* </label>
<!--<input class="error" type="subject" name="subject" value="" size="40" required>
<small class="error">Invalid entry</small>-->
<select id="customDropdown1" class="medium error" name="subject" required="" data-invalid="">
<option value="">Select an option...</option>
<option value="first">Green Chilies</option>
<option value="second">Raisins</option>
<option value="third">Panko bread crumbs</option>
<option value="fourth">Assistance</option>
</select>
<small class="error">Invalid entry</small>
</div>
<!-- End Contact Form -->
</div>
PHP:
<?php
$to = "education#arcdna.com";
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
mail($to , $subject, $message, $email);
echo "Thank you for using our mail form";
?>
None of your input fields have a name associated with them, so you're likely getting empty data in your POST. The 'email' value within $_POST['email'] refers to an input field's name.
Specifically, you're not getting an email address from your form, so the email is not sending to anyone.
For instance, you'll need:
<input type="email" name="email" required>
The fourth parameter of mail() is additional headers. Which is where your "FROM" information should go.
Refer here:
http://php.net/manual/en/function.mail.php
for what should go there.
here's one example
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Categories