I've gone thru tons of the forms and cant seem to find the answer. I have been working on this problem with my php form on and off for days. hope to find help here. the form is working perfect. all the fields are working correct upon submit, but there always seems to be a second form sent out from a day to two days later that is blank. If there is any suggestions to why this occurs it would be helpful.
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$comments = $_POST['comments'];
// recipient address
$to = "grandforkssuites#gmail.com";
// subject of email
$re = "Contact Us Form Delivery";
// message creation
$contact = "Name:".$name."\nEmail:".$email."\nSubject:".$subject."\r\n";
$txt = "Comments:".$comments."\r\n";
$fmsg = $contact."\r\n".$txt;
$msg = wordwrap($fmsg, 70);
// send email
mail($to,$re,$msg);
?>
<form action="contact1.php" method=post name="form" id="form">
<div class="col_w280 float_l">
<p><em>
<label for="author">Name:</label> <input type="text" id="name" name="name" class="required input_field" />
<div class="cleaner_h10"></div>
<label for="email">Email:</label> <input type="text" id="email" name="email" class="validate-email required input_field" />
<div class="cleaner_h10"></div>
<label for="email">Phone:</label> <input type="text" id="phone" name="phone" class="required input_field" />
<div class="cleaner_h10"></div>
<label for="subject">Subject:</label> <input type="text" name="subject" id="subject" class="input_field" />
<div class="cleaner_h10"></div>
</div>
<div class="col_w280 float_r">
<label for="text">Comments:</label> <textarea id="comments" name="comments" rows="0" cols="0" class="required input_field"></textarea>
<div class="cleaner_h10"></div></em></p>
<input name=submit type=submit id="submit" onClick="MM_validateForm('name','','R','email','','RisEmail');return document.MM_returnValue" value="Send">
</div></form>
Add validation to the PHP, else even if no values was sent via POST, just by visiting the page its going to send a blank email. Most likely a search engine or such bot is just crawling.
So check its POST
<?php
if($_SERVER['REQUEST_METHOD']==='POST'){
//put code here
}
?>
and check your values are set min-max length ect
<?php
...
...
...
//Comments
if(empty($_POST['comments'])){
//comments empty, do or set something
}else if(strlen($_POST['comments']) < 5){
//not long enough, do or set something
}else if(strlen($_POST['comments']) > 50){
//too large, do or set something
}
?>
and most importantly check email is really an email..
<?php
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)){
//is an email
}else{
//not an email
}
?>
Also your want to add a basic captcha else your be enjoying 1000s of marketing/spam emails per day.
Good luck, implementing it.
Related
So I've had some issues trying to get my php code to work. I found a form php handler which I want to send the email on the back end for the users.
<?php
if(isset($_POST['submit'])){
ob_start();
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['first_name'];//Sender first name//
$last_name = $_POST['last_name'];//sender last name//
$subject = "Contact Request.";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$to = "-myemail#outlook.com-"; // this is your Email address
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
header('Location: http://-mysite-/thankyou.html');
exit();
}
?>
Here is the HTML form info:
<form action="php/email.php" method="post" name = "email form" enctype="multipart/form-data" class="container" align="center">
<label for="firstname"></label>
<strong>*</strong><input type="text" placeholder="Enter First Name" name="first_name" required>
<br>
<label for="lastname"></label>
<strong>*</strong><input type="text" placeholder="Enter Last Name" name="last_name" required>
<br>
<label for="email"></label>
<strong>*</strong><input type="text" placeholder="Enter Email" name="email" required>
<br>
<label for="phoneno"></label>
<input type="phoneno" placeholder="Enter Phone Number" name="phone_number">
<br>
<label for="interested"></label>
<t> Brief description of project:</t><br>
<textarea style="width:100% height:60%" align="center" name="message">
</textarea><br>
<button type="submit" class="btn" value="Send Form"><strong>Submit</strong></button>
</form>
I can't figure out why the page on submit does redirect to the email.php but doesn't do anything from there. Do I need to contact the site support team to restart my php services? I've been smacking my head against the keyboard for the last 2 days as to why this isn't working.
Because you haven't field in your form with name="submit" and trying to get its value in PHP: if(isset($_POST['submit'])).
Bonus tip: don't use name submit for any field of the form, cause some browsers getting fooled with this. Instead use formsubmit, submitted or anything else.
just add this field in your form
<input type="hidden" name="submitted" value="1">
andchange condition in PHP to
if(isset($_POST['submitted']) && intval($_POST['submitted']) == 1)...
I am trying to make my own HTML / CSS form processed with PHP. The form has no errors that I can tell, just something going wrong with the PHP. I am not receiving the message from the form. I'm new with PHP and trying to learn about it. Any help is appreciated.
HTML form:
<form class="grn-background" action="processing.php" method="post">
<label for="fullname">Full Name</label>
<input id="fullname" name="fullname" type="text">
<label for="email">Email Address</label>
<input id="email" name="email" type="email">
<label for="message">Message</label>
<textarea id="message" name="message"></textarea>
<input type="submit" value="Send Message">
</form>
processing.php file
$full_name = $_POST['fullname'];
$email = $_POST['email'];
$message = $_POST{'message'};
$to = 'services#brentnicolet.com';
$subject = 'BNWS Contact Form Submission';
$form_message = "$message";
mail($to, $subject, 'From' . $email);
echo 'Thank you' . $full_name . '. We have received your message and will respond within the next 24 - 48 hours.';
?>
look at https://github.com/PHPMailer/PHPMailer for minimum requirement to run php-mailer
also note if you are using localhost - it will not work, as well as on github. It works when you have it on the hosted website.
I've been learning PHP for about two days now. So I'm really new to PHP. I have tried my best to understand but no matter what I write, my code never works. I got it to send an email successfully one time. But I'm not able to get it to send the contents in my form.
Here is my HTML form.
<!-- FORM BEGINS -->
<form action="contact-form-handler.php" method="post">
<!-- Full Name -->
<div class="formWrapper ">
<label name="firstname" for="firstName"><span>*</span>First Name</label>
<input type="text" name="memberFirstName" id="memberFirstName" onkeyup="activateButton()" class="inputText" tabindex="1" maxlength="256" onkeydown="return checkAlphaNumericText(event,this);" required="required"/>
</div>
<p class="fieldsetDivider"></p>
<div class="formWrapper">
<label for="lastName"><span>*</span>Last Name</label>
<input type="text" name="memberLastName" id="memberLastName" onkeyup="activateButton()" class="inputText" tabindex="2" maxlength="256" onkeydown="return checkAlphaNumericText(event,this);" required="required"/>
</div>
<p class="fieldsetDivider"></p>
<!-- Date of Birth-->
<p class="fieldsetDivider"></p>
<div class="formWrapper smallInput">
<label for="firstInput"><span>*</span>Date of Birth
<div class="labelClarify">(MM/DD/YYYY)</div>
</label>
<div class="inlineInput">
<input type="text" name="month" id="month" maxlength="2" onkeyup="activateButton();autotab(this, 'day')" onkeypress="return isNumberKey(event)" class="inputText" placeholder="MM" required="required"/>
<span>/</span>
</div>
<div class="inlineInput">
<input type="text" name="day" id="day" maxlength="2" onkeyup="activateButton();autotab(this, 'year')" onkeypress="return isNumberKey(event)" class="inputText" placeholder="DD" required="required"/>
<span>/</span>
</div>
<div class="inlineInput">
<input type="text" name="year" id="year" maxlength="4" onkeyup="activateButton()" onkeypress="return isNumberKey(event)" class="inputText" placeholder="YYYY" required="required"/>
</div>
<a rel="Please enter your date of birth" class="formHelp tooltip-link" href="#">
<img src="../../images/site3/common/form_icon_help.png">
</a>
</div>
<p class="fieldsetDivider"></p>
<!-- Member ID -->
<div class="formWrapper">
<label for="memberID"><span>*</span>Member ID</label>
<div class="inlineInput">
<input type="text" name="memberID" id="memberID" class="inputText" onkeyup="activateButton()" tabindex="3" maxlength="9" onkeypress="return isNumberKey(event)" required="required"/>
</div>
<a rel="Please enter your member ID" class="formHelp tooltip-link" href="#">
<img src="../../images/site3/common/form_icon_help.png">
</a>
</div>
<p class="fieldsetDivider"></p>
<!-- Zip Code -->
<div class="formWrapper">
<label for="zipCode"><span class="requiredStar">*</span>Zip Code</label>
<div class="inlineInput">
<input type="text" name="memberZipCode" id="memberZipCode" onkeyup="activateButton()" tabindex="4" class="inputText" maxlength="5" onkeypress="return isNumberKey(event)"/>
</div>
</div>
<p class="fieldsetDivider"></p>
<!-- Button -->
<div class="button">
<button class="greenBtnLarge" type="submit" style="text-decoration:none;"><span>Next<span></button>
</div>
</form>
<!-- FORM ENDS -->
Can someone please help me with a php code that would work for this form? I have found a couple template forms on the internet and I've spent hours trying to modify them to work with my form. But no luck.
And I can get the PHP and form to work together and make it send me an email from my server, so there's no problem with the server. An email will send. I just can't get the PHP code to send the contents of the form. It sends the email, but with no form details. Understand?
I really, really need help with this. Can you guys help me create a PHP code that will work with my HTML form I posted in this thread? I really need to get past this step in this project.
Thank you!
UPDATE!
Here is PHP template I found on the internet, but I don't know how to really modify it properly.... please help?
<?php
$errors = '';
$myemail = 'example#example.com';//<-----Put Your email address here.
if(empty($_POST['firstname']) ||
empty($_POST['lastname']) ||
empty($_POST['dob']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['firstname'];
$email_address = $_POST['lastname'];
$message = $_POST['dob'];
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 = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n Email: $email_address \n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Contact form handler</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
You have a several code errors...
Remove the <label> tags from your titles for <input type="text">... they are not needed.
Make sure your form field name matches your email code $_POST['something'] for example
You have <input type="text" name="memberFirstName" id="memberFirstName" /> in your form... BUT
you have $_POST['firstname'] in your email code. Change $_POST to memberFirstName OR change your <input name and id to firstname
The same changes need to be made to all elements so they match precisely.
AND remember... PHP is case sensitive.
The HTML form fields are not the same with the fields in php email handler
Ex.
The input name should be same as what the handler should get
Since
<input type="text" name="memberFirstName" required="required"/>
The index of $_POST should be same memberFirstName
$_POST['memberFirstName']
This should be applied to all fields
It seems the HTML form is not related to the php handler at all.
Its better to use this form for testing instead
<form action="contact-form-handler.php" method="POST">
First Name: <input name="firstname" type="text"><br>
Last Name:<input name="lastname" type="text"><br>
DOB: <input name="dob" type="text">
<button type="submit">Send</button>
</form>
Note:
If you are using wamp or xampp local server you need to check if the email service is configured correctly otherwise no email will be sent
Check this for reference:
How to configure XAMPP to send mail from localhost?
When I am filling out the contact form on the website that I am making, the e-mail will be sent, but I am not receiving it in the inbox of my computer.
The code looks like this:
HTML:
<div id="form">
<form action="mailto:psteintj#xs4all.nl" id="contactForm" method="post">
<span></span>
<input type="text" name="name" class="name" placeholder="Enter your name" tabindex=1 />
<span></span>
<input type="text" name="email" class="email" placeholder="Enter your email" tabindex=2 />
<span id="captcha"></span>
<input type="text" name="captcha" class="captcha" maxlength="4" size="4" placeholder="Enter captcha code" tabindex=3 />
<span></span>
<textarea class="message" placeholder="Enter your message" tabindex=4></textarea>
<input type="submit" name="submit" value="Send e-mail" class="submit" tabindex=5>
</form>
</div>
JS:
if ((captchaVal == captchaCode) && (emailFilter.test(emailText)) && (nameFilter.test(nameText)) && (messageText > 50)) {
$.post("mail.php", {
name: $(".name").val(),
email: $(".email").val(),
message:$(".message").val()
});
$("#contactForm").css("display", "none");
$("#form").append("<h2>Message sent!</h2>");
return false;
}
and PHP:
<?php
$name = $POST['name'];
$email = $_POST['email'];
$message = $POST['message'];
Could someone tell me where I am going wrong?
Well, you are not sending any emails (or at least you haven't posted any code about it), so of course you are not receiving any emails. You should configure the mailing, and use the mail function.
The function needs a working SMTP server to actually send out the e-mail.
Your PHP has no mail() call or similar? I'm probably missing something here.
I currently have this page I am working on:
http://www.webauthorsgroup.com/new/template/index3.html
In the lower right corner is a form (php), but I can't "echo" a text message after it has been submitted (for whatever reason).
My form is:
<form id="contact" method="post" action="">
<fieldset>
<label for="name">Name</label>
<input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required">
<label for="email">E-mail</label>
<input name="hidden" class="required email" onblur="if(value=='<?php echo htmlentities($_POST['email']); ?>') value = 'Your Email'" onfocus="if(value=='Your Email') value = ''" type="email" value="Your Email" placeholder="yourname#domain.com">
<label for="phone">Phone</label>
<input name="phone" onblur="if(value=='<?php echo htmlentities($_POST['phone']); ?>') value = 'phone'" onfocus="if(value=='phone') value = ''" type="tel" value="phone" placeholder="ex. (555) 555-5555">
<input type="hidden" name="phone" placeholder="ex. (555) 555-5555">
<label for="message">Question/Comment</label>
<textarea name="message" onblur="if(value=='<?php echo htmlentities($_POST['message']); ?>') value = 'message'" onfocus="if(value=='message') value = ''" value="message" placeholder="Message"></textarea>
<input type="submit" name="submit" class="button" id="submit" value="Send Message" />
</fieldset>
</form>
=========================================================
the process.php is:
<?php
if(isset($_POST['submit']))
{
// Get Data
$name = strip_tags($_POST['name']);
$email = strip_tags($_POST['email']);
$phone = strip_tags($_POST['phone']);
$url = strip_tags($_POST['url']);
$message = strip_tags($_POST['message']);
echo "Thank You!";
}
// Send Message
mail( "bruce#webauthorsgroup.com", "Inquiry From WebAuthorsGroup",
"Name: $name\nEmail: $email\nPhone: $phone\nWebsite: $url\nMessage: $message\n",
"From: Forms <forms#example.net>" );
?>
=================================================
I need the "message sent" text echoed in the same div after submitting the form and I don't want to convert my index page to index.php
Any help would be great!
The PHP code on the page index3.html is not being parsed or executed by the PHP interpreter on your server because the file extension is .html. Go ahead and view source on that page in the browser. Note that you can see the PHP code. You should not be able to see PHP code in the HTML source. You should see only the HTML rendered by the PHP. Please change the file extension to .php so your server can execute it instead of outputting it as text.