I've got 2 contact forms on a site. One is for simple contact-us and the other is for a registration. I've got them pointing to two different php and js files. The contact-us form is working, but I can't get the registration form to work. Here's the php:
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phoneNumber']) ||
empty($_POST['childFirstName']) ||
empty($_POST['childLastName']) ||
empty($_POST['childAge']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
// create email body and send it
$to = 'lloyd.leeiv#yahoo.com';
$email_subject = "Contact form submitted by: $name";
$email_body = "You have received a new message. \n\n".
" Here are the details:\n \n Parent/Guardian Name: $name \n ".
"Email: $email_address \n Phone: $phoneNumber \n Child's Name: $childFirstName $childLastName \n Age: $childAge";
$headers = "From: JNGSO#jngso.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
And the HTML:
<form name="sentMessage" class="well" id="contactForm" novalidate>
<p>Parent/Guardian Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control"
placeholder="Parent/Guardian Name" id="name" required
data-validation-required-message="Please enter your name" />
<p class="help-block"></p>
</div>
</div>
<p>Email Address</p>
<div class="control-group">
<div class="controls">
<input type="email" class="form-control" placeholder="Email"
id="email" required
data-validation-required-message="Please enter your email" />
</div>
</div>
<p>Phone Number</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Phone Number"
id="phoneNumber" required
data-validation-required-message="Please enter your phone number" />
</div>
</div>
<p>Child's First Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's First Name"
id="childFirstName" required
data-validation-required-message="Please enter your child's first name" />
</div>
</div>
<p>Child's Last Name</p>
<div class="control-group">
<div class="controls">
<input type="text" class="form-control" placeholder="Child's Last Name"
id="text" required
data-validation-required-message="Please enter your child's last name" />
</div>
</div>
<p>Child's Age</p>
<div class="control-group">
<div class="controls">
<input type="number" class="form-control" placeholder="Child's Age"
id="number" required
data-validation-required-message="Please enter your child's age" />
</div>
</div>
<p>Boy or Girl?</p>
<div class="control-group">
<label class="radio-inline">
<input type="radio" name="boyGirl" id="boy" value="Boy"> Boy
</label>
<label class="radio-inline">
<input type="radio" name="boyGirl" id="girl" value="Girl"> Girl
</label>
</div>
<div id="success"> </div>
<button type="submit" class="btn btn-lg btn-success pull-right">Send</button><br />
</form>
I've got the proper script links on the page (changed the name to point to the correct js file) and in the js file I'm pointing to the correct php url. Like I said, it works with the contact-us form but not this one. I can't figure out what I'm missing!
Okay, so I threw this question up in desperation (because I'm new to php and I didn't think I could solve it). After carefully examining it, it's actually pretty simple! doh!
I just had to make sure all of the id's were labeled, all of the var were accounted for and everything matched up in my php. For example, you can see above I have:
....
$message = $_POST['phoneNumber'];
$message = $_POST['childFirstName'];
$message = $_POST['childLastName'];
$message = $_POST['childAge'];
....
in my php where I should have each of those labeled differen't (not each one as $message).
I'm sorry if this wasted anyone's time, but hopefully someone can find this useful.
Related
I am using Ampps on Mac and trying to send an email using php from a contact form however I do not receive the mail and when the form is submitted it redirects me to the file page resulting in a blank display
my form :
<form action="email.php" method="post">
<div class="col-md-6 w3_agileits_contact_left">
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-22" name="Name" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-22">
<span class="input__label-content input__label-content--akira">Your name</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="email" id="input-23" name="Email" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-23">
<span class="input__label-content input__label-content--akira">Your email</span>
</label>
</span>
<span class="input input--akira">
<input class="input__field input__field--akira" type="text" id="input-24" name="Subject" placeholder="" required="" />
<label class="input__label input__label--akira" for="input-24">
<span class="input__label-content input__label-content--akira">Your subject</span>
</label>
</span>
</div>
<div class="col-md-6 w3_agileits_contact_right">
<div class="w3_agileits_contact_right1">
<textarea name="Message" id="Message" placeholder="Your comment here..." required=""></textarea>
</div>
<div class="w3_agileits_contact_right2">
<input type="submit" value="Send">
</div>
<div class="clearfix"> </div>
</div>
<div class="clearfix"> </div>
</form>
my File :
$email = $_POST['Email'];
$name = $_POST['Name'];
$to = "lucvanrooyen#gmail.com";
$subject = $_POST['Subject'];
$userMessage =$_POST['Message'];
$headers = "From: $email\n";
$message = "$name has sent you the following message.\n
Message: $userMessage";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: lucvanrooyen#gmail.com\n";
$usermessage = "Thank you for your enquiry we will be in touch.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
The code you have shown is not enough to debug your problem.
If you are using the mail method which is built into the standard library, read this answer to find out a few troubleshooting steps you could follow.
If you are and are still finding it difficult to use, then you could consider using one of the PHP emailing solutions like -
PHPMailer
SwiftMailer
Please check your form tag. there is no opening tag for form
<form action="email.php" method="post">
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I have designed a form in html and I'm using php to send it to my email. The form validates OK and everything is fine apart from the fact that it doesn't send some information. Here is how it comes to my email:
Name:
Email:
Tel.:
Message: test
So when I fill it in the only field that goes through is the "Message" field. The other ones are blank although the form validates and process. I guess there is something in php code. I don't know much about php, so need some help please. Thanks.
<form action="post.php" method="post">
<div class="form-group">
<label for="name">Name *</label>
<input type="text" class="form-control" id="name"
placeholder="" required="required" oninvalid="this.setCustomValidity('Please enter your name')"
oninput="setCustomValidity('')">
</div>
<div class="form-group">
<label for="email">E-mail *</label>
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-envelope"></span>
</span>
<input type="email" class="form-control" id="email" placeholder="" required="required"
oninvalid="this.setCustomValidity('please enter your email')" oninput="setCustomValidity('')">
</div>
</div>
<div class="form-group">
<label for="name">phone *</label>
<input type="text" class="form-control" id="phone"
placeholder="" required="required" oninvalid="this.setCustomValidity('please enter your phone')"
oninput="setCustomValidity('')">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label for="name">message *</label>
<textarea name="message" id="message" class="form-control"
rows="10" cols="25" required="required" placeholder="" oninvalid="this.setCustomValidity('please enter your message')"
oninput="setCustomValidity('')"></textarea>
</div>
</div>
<div class="col-md-12">
<button type="submit" class="btn btn-primary pull-right" id="btnContactUs">send</button>
</form>
and php code:
<?php
$addressto = "info#xxx.com";
$subject = "Message from the website";
$content = "Name: ".$_POST['name']."\n"
."Email: ".$_POST['email']."\n"
."Tel.: ".$_POST['phone']."\n"
."Message: ".$_POST['message']."\n";
if(!$_POST['name'] || !$_POST['email'] || !$_POST['message']){
header("Location: contact.html");
}
$email = $_POST['email'];
if (mail($addressto, $subject, $content, 'Od: <' . $email . '>')) {
header("Location: contact-ok.html");
}
?>
Your input fields are missing the name attribute
id is mostly for JS/CSS manipulation, while name will be the keys in your POST array.
They can both be the same. Hence why your message works.
Remember that JS validation can easily be bypassed and that the user input should also be checked in php.
<input type="text" class="form-control" id="name" name="name"...>
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 know this may have been submitted before (sorry)
I have basic form, these are the details id like to be sent, however i cannot get the reCaptcha to work with it. I have googled all day, but when i try other peoples code (amending to fit mine) it doesnt seem to work.
I would like: Name, Email, Number, newsletter (yes/no) and recaptcha to be sent/work.
Can someone please give me an idea where i may be going wrong? what i may need to add?
Thanks in advance!
Here is my Form (html)
<form method="POST" action="Form_Activation.php">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Full Name" value="" required/>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="email" value="" placeholder="you#example.com" required/>
</div>
<div class="form-group">
<label for="number">Number:</label>
<input class="form-control" name="number" id="number" value="" placeholder="Contact Number" required/>
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" id="message" placeholder="Enter Message.." required></textarea>
</div>
<div class="form-group">
<input type="checkbox"/> <b> Subscribe to Newsletter</b>
</div>
<div class="g-recaptcha" data-sitekey="6Le2SBQTAAAAADIOrUEPpcEVvR_c0vN9GzQpLg05"></div>
<button type="submit" class="btn btn-default sendbutton">SEND</button>
</form>
Here is my php (basic)
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
//$password = $_POST['password'];
//$keyy = $_SERVER['UNIQUE_ID'];
$msg = "Name: $name\r\n \r\n";
$msg .= "Email: $email\r\n \r\n";
$msg .= "Number: $number\r\n \r\n";
$msg .= "Message: $message\r\n \r\n";
$recipient = "info#islandwebdesign.co.uk";
$subject = "New Website Request";
$mailheaders = "From:$email";
//$mailheaders .= "Reply-To:$email";
mail($recipient,$subject,$msg,$mailheaders);
header("Location: contactus.php?msg=1");
?>
First of all make sure that you've included the necessary JavaScript resource to render reCAPTCHA widget properly, like this:
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<form action="?" method="POST">
<div class="g-recaptcha" data-sitekey="your_site_key"></div>
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
Here's the reference:
Displaying the widget
Now comes to your user's response. The response from the user's captcha challenge can be fetched in three ways. It can be as,
Now comes to your user's response. The response from the user's captcha challenge can be fetched in three ways. It can be as,
g-recaptcha-response - a POST parameter in the submitted form
grecaptcha.getResponse(widget_id) - will provide the response after the user completes the captcha.
A string argument to the callback function specified in the config object passed to the render method.
Here's the reference:
Verifying the user's response
For your purpose use g-recaptcha-response to get the user's response. So your code should be like this:
HTML
<form method="POST" action="Form_Activation.php">
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Full Name" value="" required/>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" id="email" name="email" value="" placeholder="you#example.com" required/>
</div>
<div class="form-group">
<label for="number">Number:</label>
<input class="form-control" name="number" id="number" value="" placeholder="Contact Number" required/>
</div>
<div class="form-group">
<label for="message">Message:</label>
<textarea class="form-control" name="message" id="message" placeholder="Enter Message.." required></textarea>
</div>
<div class="form-group">
<input type="checkbox"/> <b> Subscribe to Newsletter</b>
</div>
<div class="g-recaptcha" data-sitekey="6Le2SBQTAAAAADIOrUEPpcEVvR_c0vN9GzQpLg05"></div>
<button type="submit" name="submit" class="btn btn-default sendbutton">SEND</button>
</form>
Add a name attribute in your submit button.
Form_Activation.php
<?php
if(isset($_POST['submit'])){
//your site secret key
$secret = 'XXXXXXX_Secret-key_XXXXXXX';
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){
//get verified response data
$param = "https://www.google.com/recaptcha/api/siteverify?secret=".$secret."&response=".$_POST['g-recaptcha-response'];
$verifyResponse = file_get_contents($param);
$responseData = json_decode($verifyResponse);
if($responseData->success){
// success
$name = $_POST['name'];
$email = $_POST['email'];
$number = $_POST['number'];
$message = $_POST['message'];
// so on
}else{
// failure
}
}
}
?>
Don't forget to add your secret key in $secret variable.
I've got a twitter bootstrap modern business website and would like to add two fields to the form. The form says its been sent but nothing is received.
Heres my form and contact-me.php
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group form-group">
<div class="controls">
<label>Full Name:</label>
<input type="text" class="form-control" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Foo:</label>
<input type="text" class="form-control" id="foo" required data-validation-required-message="foo.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Foo2:</label>
<input type="text" class="form-control" id="foo2" required data-validation-required-message="foo2.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Phone Number:</label>
<input type="tel" class="form-control" id="phone" required data-validation-required-message="Please enter your phone number.">
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Email Address:</label>
<input type="email" class="form-control" id="email" required data-validation-required-message="Please enter your email address.">
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Message:</label>
<textarea rows="10" cols="100" class="form-control" id="message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
</div>
</div>
<div id="success"></div>
<!-- For success/fail messages -->
<button type="submit" class="btn btn-primary">Send Message</button>
</form>
and my contact-me-php
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['foo']) ||
empty($_POST['foo2']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$foo = $_POST['foo'];
$foo2 = $_POST['foo2'];
$phone = $_POST['phone'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'foo#foo.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Modern Business Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new message from your website's contact form.\n\n"."Here are the details:\n\nName: $name\n\nfoo: $foo\n\nfoo2: $foo2\n\nPhone: $phone\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply#your-domain.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Inspect, verify and filter POST data to see whether data is coming through correctly
Verify you can send mails from the server you are using and configuration (SMTP etc.) is correctly set up
Consider using a mail library instead of manually working with error-prone mail headers, body contents and all that is involved
Your emails might be classified as spam and thus not getting through
I think you should have a "name" attribute to your inputs. They are not valid controls, source
Thanks for your help. I put firebug on and found out I was missing the POST data. After a bit of head scratching I found I had to edit my contact_me.js as well (it helpfully say not to edit it in the template) Thanks again!
I've been looking around everywhere and cannot seem to find how to make this work - it is simply not sending an email to my address. Here is my HTML form:
<form id="contactMe" name="contact" method="post" novalidate="novalidate">
<fieldset>
<label for="name" id="name">Name<span class="required">*</span></label>
<input type="text" name="name" id="name" size="30" value="" required="">
<label for="email" id="email">Email<span class="required">*</span></label>
<input type="text" name="email" id="email" size="30" value="" required="">
<label for="phone" id="phone">Phone</label>
<input type="text" name="phone" id="phone" size="30" value="">
<label for="Message" id="message">Message<span class="required">*</span></label>
<textarea name="message" id="message" required=""></textarea>
<label for="Answer" id="answer">Name the house pet that says “<i>woof</i>“<span class="required">*</span></label>
<input type="text" name="answer" value="" required=""></br>
<input id="submit" type="submit" name="submit" value="Send">
</fieldset>
<div id="success">
<span class="green textcenter">
<p>Your message was sent successfully! I will be in touch as soon as I can.</p>
</span>
</div> <!-- closes success div -->
<div id="error">
<span><p>Something went wrong, try refreshing and submitting the form again.</p></span>
</div> <!--close error div-->
</form>
and here is my PHP saved as mailer.php:
<?php
$to = "someone#gmail.com";
$from = $_REQUEST['email'];
$name = $_REQUEST['name'];
$headers = "From: $from";
$subject = "You have a message from your.";
$fields = array();
$fields{"name"} = "name";
$fields{"email"} = "email";
$fields{"phone"} = "phone";
$fields{"message"} = "message";
$body = "Here is what was sent:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
mail("maytee.kneitz#gmail.com",$subject,$message,"From: $from\n");
echo 'Mail sent';
?>
This is my first shot at working on a mailer / contact form, so sorry if it's a blatant problem. I just can't seem to find it. Any guidance would be appreciated.
I do have validation in my scripts (not posted here).
You don't have a form action defined. Try this:
<form id="contactMe" name="contact" method="post" action="mailer.php" novalidate="novalidate">
By default, the form will be submitted to its current location unless otherwise specified. In your case, point it to wherever your mail script is located