I have a form on my site. When the user submits the form I get the email response but there is no form data returned. All I see is
Company:
Name:
Email:
Phone:
The form html is below:
<form method="post" action="send_survey.php" class="survey" >
<header><img src="../img/PTS_Survey_logo.jpg" alt="Patterson Tubular Services Logo">
Customer Survey</header>
<fieldset>
<section>
<label class="input">
<i class="icon-append icon-group"></i>
<input type="company" id="company" required placeholder="Company name">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-user"></i>
<input type="name" id="name" required placeholder="Your name" >
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-envelope-alt"></i>
<input type="email" id="email" required placeholder="Your e-mail">
</label>
</section>
<section>
<label class="input">
<i class="icon-append icon-phone"></i>
<input type="phone" id="phone" placeholder="Your phone number">
</label>
</section>
</fieldset>
<footer>
<input id="submit" name="submit" type="submit" value="submit" class="button">Submit the survey</button>
</footer>
</form>
The php code is below:
<?php
/*Subject and email variables */
$emailSubject = 'PTS Site Test';
$emailTo = 'testemail#testemail.com';
/* Gather form information */
$company = $_POST['company'];
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$body = <<<EOD
<br><hr><br>
Company: $company <br>
Name: $name <br>
Email: $email <br>
Phone: $phone <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail ($emailTo, $emailSubject, $body, $headers);
/* Results rendered */
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=http://www.cudd.com/PTS-2014/index.html">';
?>
Thank you in advance.
HTML form input is set in POST by the element's name attribute, not its id. You should set the name attribute to the same as the id on each of your input elements.
You have no name attribute on any of your inputs
Change:
<input type="company" id="company" required placeholder="Company name">
To:
<input type="company" name="company" id="company" required placeholder="Company name">
Related
I have designed an email for a cart page in this website. When checkout is clicked nothing happens. Instead it displays an empty page with a different header.
PHP:
<?php
$subject = "An order has been placed on your website";
if (isset($_POST['button '])) {
$firstName = $_POST['first-name'];
$lastName = $_POST['last-name'];
$mailFrom = $_POST['email'];
$address = $_POST['address'];
$productName = $_POST['product-name'];
$quantity = $_POST['quantity'];
$phone = $_POST['tel'];
$mailTo = "admin#onlineooty.co.in";
$headers = "From: ".$mailFrom;
$txt = "you have recieved a mail from ".$firstName.".\n\n"."whose address is : ".$address.".\n\n"."the product name is: ".$productName."\n\n"."the phone number is: ".$phone;
mail($mailTo, $subject, $txt, $headers );
header("Location: cart.php?mailsend");
}
?>
My form:
<form class="emailForm" action="email.php" method="post">
<div class="input-checkbox">
<div class="caption">
<div class="form-group">
<input class="input" type="text" name="first-name" placeholder="First Name">
</div>
<div class="form-group">
<input class="input" type="text" name="last-name" placeholder="Last Name">
</div>
<div class="form-group">
<input class="input" type="email" name="email" placeholder="Email">
</div>
<div class="form-group">
<input class="input" type="text" name="address" placeholder="Address">
</div>
<div class="form-group">
<input class="input" type="text" name="product-name" placeholder=" product required">
</div>
<div class="form-group">
<input class="input" type="number" name="quantity" placeholder="quantity in kgs" max="10">
</div>
<div class="form-group">
<input class="input" type="text" name="pin-code" placeholder="Pin Code">
</div>
<div class="form-group">
<input class="input" type="tel" name="tel" placeholder="phone">
</div>
</div>
</div>
</div>
<div class="payment-method">
<span>Kindly proceed with the payment to get order confirmation <font color="red">*No refund provided after order confirmation*</font></span>
<div class="input-radio">
<label for="payment-2">
<span>We do accept payments only on Google Pay as of now.
</span>
Google Pay
</label>
<div class="caption">
<p>We do accept payments on <font color = "blue">GPay
</font>, you can pay us on this number <strong>123456789
</strong>.
</p>
</div>
</div>
<button class="submit-button" type="submit" name="button">Checkout
</button>
</form>
Remove the space, your code should be like this:
<?php
$subject = "An order has been placed on your website";
if (isset($_POST['button'])){
$firstName = $_POST['first-name'];
$lastName = $_POST['last-name'];
$mailFrom = $_POST['email'];
$address = $_POST['address'];
$productName = $_POST['product-name'];
$quantity = $_POST['quantity'];
$phone = $_POST['tel'];
$mailTo = "admin#onlineooty.co.in";
$headers = "From: ".$mailFrom;
$txt = "you have recieved a mail from ".$firstName.".\n\n"."whose address is : ".$address.".\n\n"."the product name is: ".$productName."\n\n"."the phone number is: ".$phone;
mail($mailTo, $subject, $txt, $headers );
header("Location: cart.php?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">
HTML:
<form class="contact_form" action="php/mail.php" method="post" name="contact_form">
<ul>
<li>
<label for="name">Name*</label>
<input type="text" placeholder="Your Name" required />
</li>
<li>
<label for="name">Email*</label>
<input type="email" name="email" placeholder="Your email address" required />
<span class="form_hint">Proper format "name#something.com"</span>
</li>
<li>
<label for="name">Website</label>
<input type="url" name="website" placeholder="Your website" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="message">Message:</label>
<textarea rows="6" cols="40" name="message" ></textarea>
</li>
<li>
<button class="submit" type="submit">Send</button>
</li>
</ul>
</form>
HTML
/* Subject and Email Variables */
$emailSubject = 'Contact Form';
$webMaster = 'email#address.com';
/* Gathering Data Variables */
$nameField = $_POST['Name'];
$emailField = $_POST['Email'];
$website = $_POST['Website'];
$messageField = $_POST['Message'];
$body = <<<EOD
<br><hr><br>
Name: $nameField <br>
Email: $emailField <br>
Message: $messageField <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results Rendered as HTML */
There are more problems, so:
you missed name attribute at the name text input
you used incorect names, PHP is case-sensitive in keys ($_POST['name'] !== $_POST['Name']). This is the point why you received blank meesages
for attribute in labels has to correspond with input ID
Updated code:
<form class="contact_form" action="php/mail.php" method="post" name="contact_form">
<ul>
<li>
<label for="Name">Name*</label>
<input type="text" id="Name" name="Name" placeholder="Your Name" required />
</li>
<li>
<label for="Email">Email*</label>
<input type="email" name="Email" id="Email" placeholder="Your email address" required />
<span class="form_hint">Proper format "name#something.com"</span>
</li>
<li>
<label for="Website">Website</label>
<input type="url" id="Website" name="Website" placeholder="Your website" required pattern="(http|https)://.+"/>
<span class="form_hint">Proper format "http://someaddress.com"</span>
</li>
<li>
<label for="Message">Message:</label>
<textarea rows="6" id="Message" cols="40" name="Message" ></textarea>
</li>
<li>
<button class="submit" type="submit">Send</button>
</li>
</ul>
</form>
I think you got typo there, change
$headers = "From: $email\r\n";
to
$headers = "From: $emailField\r\n";
Remember to validate the $emailField to avoid injections!
Update: Now that I can see the actual HTML for the form, there is some problems.
I think for requires and ID field, so you should add one to every field in the form.
You also forgot to set name in the name text field.
Lets add the name attribute in the name field, and add the ID field (which should be done for the other fields also):
<label for="name">Name*</label>
<input type="text" placeholder="Your Name" required />
to
<label for="name">Name*</label>
<input type="text" id="name" name="name" placeholder="Your Name" required />
$_POST['Name'] is case-sensetive, so you should change your code so the variables match the names in the html.
example:
$nameField = $_POST['Name'];
should be
$nameField = $_POST['name'];
put $nameField = $_POST['Name'];
$emailField = $_POST['Email'];
$website = $_POST['Website'];
$messageField = $_POST['Message']; within a post function. After verifying $_post is not empty. on form submit.
i'm getting blank field returns in my inbox on only a portion on my form fields
like so:
From: whatevername
Email: fgsdfg#fakeysite.com
Message:
phone:
here is my code its probably something really dumb but its bugging me, so here we go.
HTML
<div class="row-item col-1_4">
<h3>Contact Form</h3>
<h4>Please fill out the form to get your free CD Replacement Kit</h4>
<!-- Success Message -->
<div class="form-message"></div>
<!-- Form -->
<form class="b-form b-contact-form" action="blast.php">
<div class="input-wrap m-full-width">
<i class="icon-user"></i>
Name
<input class="field-name" type="text" placeholder="Name (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-phone"></i>
Phone
<input class="field-phone" type="text" placeholder="Phone">
</div>
<div class="input-wrap m-full-width">
<i class="icon-envelope"></i>
Email
<input class="field-email" type="text" placeholder="E-mail (required)">
</div>
<div class="input-wrap m-full-width">
<i class="icon-pencil"></i>
Message
<input class="field-comments" type="text" placeholder="Message">
</div>
<input class="btn-submit btn colored" type="submit" value="Send">
</form>
PHP
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$formcontent=" From: $name \n Email: $email \n Phone: $phone \n Message: $message";
$recipient = "csmith#legacybrokerage.com";
$subject = "UNLIMITED ANNUITY LEADS CD BLAST";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
try this, define name= 'something' to the input field
<input class="field-name" type="text" placeholder="Name (required)" name="name">
<input class="field-phone" type="text" placeholder="Phone" name="phone">
<input class="field-email" type="text" placeholder="E-mail (required)" name="email">
your input's dose not name attribute!
<input class="field-name" type="text" placeholder="Name (required)">
correct :
<input name="from" class="field-name" type="text" placeholder="Name (required)">
I'm a total novice so please bear with me :)…I've managed to create a form and used PHP to send the data to an email address. However, once I click submit; the screen goes blank instead of staying on the current page and displaying a message. I'm guessing i'm missing some sort of PHP code?
Also, i'd like to use the JQuery validator plugin on my form, how can I add it without basically screwing up the form?
MY HTML:
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
MY PHP:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
PHP script that you create will return an empty page, because that script just to send email. I think you need to combine PHP script and HTML script together with PHP script in top of script to get that you want and edit form action to empty like this sample:
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
}
?>
<div>
<form id="form_id" name="form_name" action="" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
<p id="feedback"><?php echo $feedback; ?></p>
</div>
Your form will take the user to scripts/index.php. You are echoing the '$feedback' var on the page with the HTML form. Redirect from scripts/index.php using
header("location: filelocation");
exit();
You can achieve this in two ways :
1. Have php and html code in one page.
2. Use ajax to submit your form.
<div>
<form id="form_id" name="form_name" action="scripts/index.php" method="post">
<div>
<label for="name">Name: </label>
<input type="text" name="name" id="name" placeholder="John Smith" required/>
</div>
<div>
<label for="email">Email: </label>
<input type="email" name="email" id="email" placeholder="name#mail.com" required/>
</div>
<div>
<label for="message">Message: </label>
<textarea name="message" id="message" rows="5" cols="30"></textarea>
</div>
<div>
<input id="submit" type="submit" name="submit" value="submit" />
</div>
</form>
</div>
<?php
$to = 'example#gmail.com';
$subject = 'Message from The Rocket Factory';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$body = <<<EMAIL
Hi, my name is $name.
$message
From $name
My Address is $email
EMAIL;
$header = "From: $email";
if($_POST){
mail($to, $subject, $body, $header);
$feedback = 'Thanks for your message';
echo '<p id="feedback">'.$feedback.'</p>'; <-- Notice this..
}
?>
You can also use ajax in jquery ($.ajax) or javascript.