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");
}
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'm currently using an html5 website with a contact form and a php action to receive contact emails. I've tried a few different codes in my php but non have stopped the blank emails from coming. I do have google analytics enables on my code but have blocked the crawler through robot.txt. Here is my code.
PHP CODE
<?php
foreach ($_GET as $Field=>$Value) {
if($Value != ''){
$body .= "$Field: $Value\n";
}
}
$name = trim(htmlentities($_GET['name'],ENT_QUOTES,'utf-8'));
$email = trim(htmlentities($_GET['email'],ENT_QUOTES,'utf-8'));
$phone = trim(htmlentities($_GET['phone'],ENT_QUOTES,'utf-8'));
$messages = trim(htmlentities($_REQUEST['messages'],ENT_QUOTES,'utf-8'));
if (strlen($name) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
if (strlen($email) == 0 )
{
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
$to = "junior.8791#gmail.com";
$message = "Name: ".$name;
$message.="\n\nEmail: ".$email;
$message.="\n\nPhone: ".$phone;
$message .= "\n\nMessage: ".$messages;
$headers = "From: $email";
$headers .="\nReply-To: $email";
$success = mail($to, $subject, $message, $headers);
if ($success) {
echo "<script>window.location = 'http://www.mason372.org/thankyou.html'</script>";
} else {
echo "<script>window.location = 'http://www.mason372.org/error.html'</script>";
}
?>
CONTACT FORM
<form action="email.php" method="post" id="form">
<div class="5grid">
<div class="row">
<div class="6u">
<input type="text" class="name" name="name" id="name" placeholder="Name" value="" aria-describedby="name-format" required aria-required=”true” pattern="[A-Za-z-0-9]+\s[A-Za-z-'0-9]+" title="e.g.'John Doe'" required="" />
</div>
<div class="6u">
<input type="email" class="email" name="email" id="email" placeholder="Email" required="" />
</div>
</div>
<div class="row">
<div class="12u">
<input type="tel" class="tel" name="phone" id="phone" name="phone" type="text" placeholder="Phone Number" pattern="(?:\(\d{3}\)|\d{3})[- ]?\d{3}[- ]?\d{4}" required />
</div>
</div>
<div class="row">
<div class="12u">
<textarea name="messages" id="messages" placeholder="Message"></textarea>
</div>
</div>
<div class="row">
<div class="12u">
<input type="submit" class="button" value="Send Message">
<input type="reset" class="button button-alt" value="Clear Form">
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">
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.