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"...>
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:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I want to send emails without using any database that's why I was trying to send an email using PHP and HTML, but the problem is that after pressing the submit button it does not sending any emails. Here are my codes:
<form role="form" name="contactform" id="contactform" method="POST" action="send.php" enctype="multipart/form-data">
<div class="row">
<div class="col-md-6">
<div class="input-text form-group">
<input type="text" name="contact_name" class="input-name form-control" placeholder="Full Name" />
</div>
<div class="input-text form-group">
<input type="email" name="email" class="input-name form-control" placeholder="Enter Email-ID" />
</div>
<div class="input-text form-group">
<input type="text" name="contact_phone" class="input-name form-control" placeholder="Phone Number" />
</div>
</div>
<div class="col-md-6">
<div class="input-text form-group">
<input type="text" name="contact_sub" class="input-name form-control" placeholder="Subject" />
</div>
<div class="textarea-message form-group">
<textarea name="contact_message" class="textarea-message hight-82 form-control" placeholder="Message" rows="2"></textarea>
</div>
</div>
<div class="col-md-12">
<input type="submit" class="btn btn-default top-margin-10 hblack" name="Submit" value="Submit" />
</div>
</div>
</form>
and the PHP code are:
<?php
$strTo = $_POST["contact_name"];
$strSubject = $_POST["email"];
$strMessage = nl2br($_POST["contact_phone"]);
$strSub = nl2br($_POST["contact_sub"]);
$strmsg = nl2br($_POST["contact_message"]);
$body="Job-title:$title \r\n
Name:$strTo \r\n
Email:$strSubject \r\n
Phone:$strMessage \r\n
Subject:$strSub \r\n
Message:$strmsg";
$from=$strSubject;
$to='abc#abc.com'; // removed for spam protection
mail($to,$from,$body);
echo "<script> alert('Your Form has been Submitted successfully'); window.location.href='index.php'; </script>";
?>
Thanks in advance.
If you use the mail function then you will have to make some server side changes to your php settings. Most commonly these changes are found in a file called "php.ini". I encourage looking up changes needed for the mail function to work on your specific server and including details about your server and php version when searching
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I haven't written code in years, so I am going off old code from a project that is over 5 years old, so I am not surprised that it doesn't work; I would like some pointers on how to make it work, please.
Here is what I have in my HTML email form --
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
and here is what my PHP looks like --
<?php
if(isset($_POST['send'])) {
// Prepare the email
$to = ''foryourdayformals#gmail.com ';
$name = $_POST['contact_name'];
$mail_from = $_POST['contact_email'];
$subject = 'Message sent from website';
$message = $_POST['contact_message'];
$header = "From: $name <$mail_from>";
// Send it
$sent = mail($to, $subject, $message, $header);
if($sent) {
echo 'Your message has been sent successfully! Return to For Your Day, LLC Website';
} else {
echo 'Sorry, your message could not send. Please use direct email link on Contact Us page (below the map). Return to For Your Day, LLC Website';
}
}
?>
Any help is GREATLY appreciated! Thanks!
update
$to = ''foryourdayformals#gmail.com ';
to
$to = 'foryourdayformals#gmail.com';
and need to add name attribute for form . This update your form
<form action="fydcontact.php" method="post">
<div class="form-group">
<!--<label for="contact_name">Name:</label>-->
<input type="text" id="contact_name" name="contact_name" class="form-control" placeholder="Name" />
</div>
<div class="form-group">
<!--<label for="contact_email">Email:</label>-->
<input type="text" id="contact_email" name="contact_email" class="form-control" placeholder="Email Address" />
</div>
<div class="form-group">
<!--<label for="contact_message">Message:</label>-->
<textarea id="contact_message" name="contact_message" class="form-control" rows="9" placeholder="Write a message"></textarea>
</div>
<button type="submit" class="btn btn-primary" name ="send">Send</button>
</form>
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 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.