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>
Related
I am not familiar with php. I have searched similar questions to where I could not find a solution. I followed a fairly simply tutorial to add a send email functionality to a web app but I cannot get it to work as I get this error when testing to send an email to my yahoo. I would like to ask for help in figuring out a solution and or how I can make this code better. Thanks in advance
This is my error
Cannot POST /contactform.php
Here is my form code from my index.html
<form action="contactform.php" method="post">
<div class="form-group">
<input type="text" name="name" placeholder="Full Name" class="form-control" id="name">
</div>
<div class="form-group">
<input type="text" name="email" placeholder="Email" class="form-control" id="email">
</div>
<div class="form-group">
<input type="text" name="subject" placeholder="Subject" class="form-control" id="message-text"></input>
</div>
<div class="form-group">
<textarea name="message" placeholder="Message" class="form-control" id="message-text"></textarea>
</div>
<button type="submit" name="submit" class="btn btn-outline-dark">Send message</button>
</form>
And here is my contactform.php that is in the same folder as my index.html
<?php
if (isset($_POST['submit'])){
$name = $_POST['name'];
$mailfrom = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$mailTo = "myemail#yahoo.com";
$headers = "From: ".$mailfrom;
$txt = "You have received an email from ".$name.".\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>
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 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