Ive got a contact form thats using the same php code on another website and it works great, but on this one it will not work for some reason, after clicking send, it redirects me to a blank page saying "No Arguments Provided!". Below is the html and php for the form.
<!-- Contact form -->
<section id="contact_form">
<div class="container">
<div class="row">
<div class="col-md-6">
<h2> We would love to hear about your upcoming project.</h2>
<h2 class="second_heading">Get In Touch With Us!</h2>
</div>
<form role="form" class="form-inline text-right col-md-6" method="post" action="mail/contact_us.php" name="sentMessage" id="contactForm" novalidate>
<div class="form-group">
<input type="text" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class="form-group">
<textarea class="form-control" rows="5" id="msg" placeholder="Message"></textarea>
</div>
<button type="submit" class="btn submit_btn">Submit</button>
</form>
</div>
</div>
</section><!-- Contact form end -->
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['msg']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['msg'];
// create email body and send it
$to = 'myemail#address.com'; // send to: email
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact
form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:
$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#myemail.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
All your form inputs/textareas are missing the name attribute. For example:
<input type="email" class="form-control" id="email" placeholder="Email">
Needs to be
<input type="email" class="form-control" id="email" name="email" placeholder="Email">
The name attribute is what's used when submitting a form, so as you have it, PHP isn't seeing the form fields.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
Hi I have a Contact form and a PHP file that handles the email after the form is successfully filled out. For some reason I am not receiving any emails from this form. Was just curious if my code was correct.
HTML FORM:
<form method="post" role="form" name="sentMessage" id="contactForm" action="/public_html/mail/contact_me.php" novalidate>
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required >
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" name="email" required >
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" name="phone" required >
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" name="message" required ></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" class="btn btn-xl" >Send Message</button>
</div>
</form>
PHP CODE:
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'will#blacart.com';
$email_subject = "Website Contact: $name";
$email_body = "You have received a contact request from tandemmetal.com.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#tandemmetals.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
You can try to use \r\n instead of \n.
$headers = "From: noreply#tandemmetals.com\r\n";
$headers .= "Reply-To: $email_address\r\n";
According to http://php.net/manual/ru/function.mail.php
(in case, if your server on Windows).
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
please assist with my PHP form. Following this text I have both my HTML form as well as my PHP page described. I am not receiving the e-mails when I attempt to use the form on my website. I have validated that my e-mail address is working, and that should not be the issue.
The following is my HTML form:
<!-- Contact Form -->
<div class="col-md-6 col-sm-6">
<hr>
<p>Have a question or comment? Fill out the form below.</p>
<div class="contact-form wow fadeInLeft showdelay2">
<form name="sentMessage" id="contactForm" novalidate>
<div class="control-group form-group">
<div class="controls">
<label>Name</label>
<input type="text" class="form-control dark" id="name" placeholder="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>Email</label>
<input type="email" class="form-control dark" id="email" placeholder="Email Address" required data-validation-required-message="Please enter your email address.">
<p class="help-block"></p>
</div>
</div>
<div class="control-group form-group">
<div class="controls">
<label>Message</label>
<textarea class="form-control dark" rows="7" id="message" placeholder="Message" required data-validation-required-message="Please enter your message" maxlength="999" style="resize:none"></textarea>
<p class="help-block"></p>
</div>
</div>
<div id="success"></div>
<div class="pull-right">
<button type="submit" class="btn btn-info btn-lg">Submit</button>
</div>
</form>
<div class="clearfix"></div>
</div>
</div>
<!-- ./contact form -->
The following code is my contact_me.php page, which doesn't appear to be working.
<?php
// check if fields passed are empty
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
// create email body and send it
$to = 'email#addresss.com'; 'email#address.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Contact form from: $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\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: info#bootstrapwizard.info\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
your to string is incorrect, the valid format is:
$to = 'AdrianPham#crosshatcheatery.com,Webmaster#crosshatcheatery.com';
the headers should end with "\r\n"
$headers = "From: info#bootstrapwizard.info\r\n";
$headers .= "Reply-To: $email_address";
I have a problem with checking if a email is valid. but the weird is that i have the same form on to different pages/urls, and on one of the forms it keeps saying that the email is invalid and on the form its valid.
The form on this page works - http://night.sendme.to/about
the form on this page doesnt - http://night.sendme.to/book/jokeren
The HTML on the forms is the same
<form action="" method="post" id="myform">
<div class="form-group">
<label for="name">Navn *</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Navn" required="required">
</div>
<div class="form-group">
<label for="corp">Virksomhed</label>
<input type="text" class="form-control" id="corp" name="corp" placeholder="Virksomhed">
</div>
<div class="form-group">
<label for="email">Email adresse *</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email adresse" required="required">
</div>
<div class="form-group">
<label for="tel">Telefon *</label>
<input type="tel" class="form-control" id="tel" name="tel" placeholder="Telefon" required="required">
</div>
<div class="form-group">
<label for="message">Kommentar</label>
<textarea class="form-control" id="message" name="message" rows="10" required="required"></textarea>
</div>
<button type="submit" class="btn btn-default" id="submit">Send</button>
</form>
<div id="success" style="color:red;"></div>
The PHP is this
<?php // Here we get all the information from the fields sent over by the form.
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = 'YOURMAIL';
$subject = 'the subject';
$message = 'FROM: '.$name.' Email: '.$email.'Message: '.$message;
$header = "MIME-Version: 1.0" . "\r\n";
$header .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$header .= "from:".$_POST['email'];
if (filter_var($email, FILTER_VALIDATE_EMAIL)) { // this line checks that we have a valid email address
mail($to, $subject, $message, $header); //This method sends the mail.
echo "Your email was sent!";
echo var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));
} else {
echo "Invalid Email, please provide an correct email.";
echo var_dump(filter_var($email, FILTER_VALIDATE_EMAIL));
}
?>
The javascript is this
$(document).ready(function(){
$('#submit').click(function(){
$.post("email.php", $("#myform").serialize(), function(response) {
$('#success').html(response);
//$('#success').hide('slow');
});
return false;
});
});
Hope some one can help, why the form only works on the http://night.sendme.to/about and the others
So, to not leave this question answer-less:
In your HTML code, you actually had <form action="" method="post" id="myform"> in both pages – but in your second page, you had another <form> tag right before it … and because of this invalid HTML, the browser ignored the second form tag, and that made $("#myform").serialize() not return any data at all, because it could not find the form element with that id.
You should always validate your HTML code. This helps avoiding such errors.
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'm trying to get a HTML from to work together with PHP in order to make a form for sending a mail, but after submitting the form, PHP file is saying
Cannot POST /quotation.php
Here is my HTML code
<div id="quotation" class="reveal-modal" data-reveal>
<a class="close-reveal-modal">×</a>
<h3>Request Quotation</h3>
<p>Please fill out this information and we will contact you as soon as possilble.</p>
<form method="post" name="" action="quotation.php">
<div class="row">
<div class="large-6 columns">
<label>Name
<input type="text" name="name" placeholder="Name" />
</label>
</div>
<div class="large-6 columns">
<label>Lastname
<input type="text" name="lastname" placeholder="Lastname" />
</label>
</div>
</div>
<div class="row">
<div class="large-6 columns">
<label>Company name
<input type="text" name="company" value="" placeholder="Your company">
</label>
</div>
<div class="large-6 columns">
<label>E-mail
<input type="text" name="email" value="" placeholder="E-mail">
</label>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<label>Additional details
<textarea name="message" placeholder="Additional details here"></textarea>
</label>
</div>
</div>
<input class="button radius" type="submit" name='submit' value="submit">
</form>
</div>
And this is the PHP that runs the form
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$company = $_POST['company'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
$email_from = $visitor_email;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name, $lastname.\n".
"Here is the message:\n $message".
$to = "email#gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
alert("yo");
//done. redirect to thank-you page.
header('Location: index.html');
?>
I added alert and echo for submit button, but none of them appears so looks like PHP is not even running.
It would be great if someone could guide me trough this problem or point out what am I doing wrong.