php form not working - php

I cant get this to work properly. I know its something stupid but I cant find it.
<?php
$mailto = "stormygurl73#yahoo.com";
$name = ucwords($_POST['name']);
$subject = $_POST['Contact form'];
$email = $_POST['email'];
$message = $_POST['message'];
if(strlen($_POST['name']) < 1 ){
echo 'email_error';
}
else if(strlen($email) < 1 ) {
echo 'email_error';
}
else if (!eregi("^[A-Z0-9._%-]+#[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
echo 'email_error';
}
else if(strlen($message) < 1 ){
echo 'email_error';
} else {
// NOW SEND THE ENQUIRY
$email_message="\n\n" .
"Name : " .
ucwords($name) .
"\n" .
"Email : " .
$email .
"\n\n" .
"Message : " .
"\n" .
$message .
"\n" .
"\n\n" ;
$email_message = trim(stripslashes($email_message));
mail($mailto, $subject, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );
}
?>
Html
<div class="wrapper">
<div id="main" style="padding:50px 0 0 0;">
<form id="contact-form" action="sendemail.php" method="post">
<h3>Get in touch</h3>
<h4>Fill in the form below, and we'll get back to you within 24 hours.</h4>
<div>
<label>
<span>Name: (required)</span>
<input placeholder="Please enter your name" type="text" tabindex="1" required autofocus>
</label>
</div>
<div>
<label>
<span>Email: (required)</span>
<input placeholder="Please enter your email address" type="email" tabindex="2" required>
</label>
</div>
<div>
<label>
<span>Message: (required)</span>
<textarea placeholder="Include all the details you can" tabindex="5" required></textarea>
</label>
</div>
<div>
<button name="submit" type="submit" id="contact-submit">Send Email</button>
</div>
</form>
<!-- /Form -->
Any help would be awesome!

You must have the name attribute on your input-elements. The first one should have
name="name"
and so on. You can read more about it here: Variables From External Sources : HTML Forms (GET and POST)

It looks like you've missed the attribute name name='somename' everywhere in your form fields. e.g.
This is what you have
<input placeholder="Please enter your name" type="text" tabindex="1" required autofocus>
This is what it should have been
<input name="name" placeholder="Please enter your name" type="text" tabindex="1" required autofocus>

Related

my form is not sending after adding functions from php [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 1 year ago.
Soi tried creating a php form and it seems not to be working, it is not sending and no action is occuring. the code below is that if the HTML
<form id="form" class="vbottom-desktop grid default-form no-spacing lined-form mb-xl" action="php\mail.php" method="post">
<div class="col-2">
<input required type="text" placeholder="Name" name="name" class="form-control">
</div>
<div class="col-2">
<input required type="email" placeholder="Email address" name="email" class="form-control">
</div>
<div class="col-2">
<textarea required placeholder="Message" name="message" class="small form-control"></textarea>
</div>
<div class="col-2">
<input id="send" type="submit" value="Send" class="btn btn-primary">
</div>
</form>
and below this is that of the php
<?php
$subject = 'You have received this businessmail from';
$to = 'okonodestine99#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = '';
if (!empty($_POST["name"])) {
$message .= 'Name: ' . $_POST['name'] . ' <br/>';
}
if (!empty($_POST["email"])) {
$message .= 'Email: ' . $_POST['email'] . ' <br/>';
}
if (!empty($_POST["phone"])) {
$message .= 'Phone: ' . $_POST['phone'] . ' <br/>';
}
if (!empty($_POST["website"])) {
$message .= 'Website: ' . $_POST['website'] . ' <br/>';
}
if (!empty($_POST["message"])) {
$message .= 'Message: ' . $_POST['message'] . ' <br/>';
}
if (#mail($to, $subject, $message, $headers))
{
echo 'sent';
}
else
{
echo 'failed';
}
?>
any possible solution to this would be highly appreciated
you should use slash not backslash in url!
try this:
<form id="form" class="vbottom-desktop grid default-form no-spacing lined-form mb-xl" action="php/mail.php" method="post">
<div class="col-2">
<input required type="text" placeholder="Name" name="name" class="form-control">
</div>
<div class="col-2">
<input required type="email" placeholder="Email address" name="email" class="form-control">
</div>
<div class="col-2">
<textarea required placeholder="Message" name="message" class="small form-control"></textarea>
</div>
<div class="col-2">
<input id="send" type="submit" value="Send" class="btn btn-primary">
</div>
</form>
and make sure you put files like this:
root
|-- yourform.html(or .php whatever is that you're using)
|-- php
|-- mail.php

PHP X-Mailer not sending all fields

I am by no means a developer. Self-taught, but can usually wing it enough to make things happen. Working on company website for boss, and having trouble with the form. Regardless of how I try to define the PHP variable, SOME are not sending the input value to the e-mail. I'm sure I'm missing something simple, thank you in advance for your help! This is what's not showing:
Website:
Average Monthly Volume:
Preferred Contact Method:
Here is what I have so far:
HTML FORM:
<div class="product-screens2">
<div style="padding:200px">
<div class="form">
<div id="sendmessage">Your message has been sent. Thank you!</div>
<div id="errormessage">Please retry.</div>
<form action="form-email" method="post" role="form" class="contactForm">
<div class="form-row">
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
<div class="validation"></div>
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="subject" id="subject" placeholder="Business Name" />
</div>
<div class="form-group col-lg-6">
<input type="text" name="name" class="form-control" id="business_site" placeholder="Business Website" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="avgvolume" placeholder="Average Monthly Volume" />
</div>
<div class="form-group col-lg-6">
<input type="text" class="form-control" name="name" id="contactmethod" placeholder="Preferred Contact Method" />
</div>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Brief Description of Goods or Services Sold"></textarea>
<div class="validation"></div>
</div>
<div class="text-center"><button type="submit" title="Send Message">SUBMIT</button></div>
</form>
</div></div>
</div>
PHP MAILER SCRIPT
<?php
/***************** Configuration *****************/
// Enter your email, where you want to receive the messages.
$contact_email_to = "Support#XXXXX.com";
// Subject prefix
$contact_subject_prefix = "Message From XXXXX Website: ";
// Name too short error text
$contact_error_name = "Name is too short or empty!";
// Email invalid error text
$contact_error_email = "Please enter a valid email!";
// Subject too short error text
$contact_error_subject = "Subject is too short or empty!";
// Message too short error text
$contact_error_message = "Too short message! Please enter something.";
/********** Do not edit from the below line ***********/
if(!isset($_SERVER['HTTP_X_REQUESTED_WITH']) AND strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die('Sorry Request must be Ajax POST');
}
if(isset($_POST)) {
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$subject = filter_var($_POST["subject"], FILTER_SANITIZE_STRING);
$message = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
$business_site = $_POST["business_site"];
$avgvolume = $_POST["avgvolume"];
$contactmethod = $_POST["contactmethod"];
if(strlen($name)<4){
die($contact_error_name);
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
die($contact_error_email);
}
if(strlen($message)<3){
die($contact_error_subject);
}
if(strlen($message)<3){
die($contact_error_message);
}
if(!isset($contact_email_from)) {
$contact_email_from = "contactform#" . #preg_replace('/^www\./','', $_SERVER['SERVER_NAME']);
}
$sendemail = mail($contact_email_to, $contact_subject_prefix . $subject,
"Name: $name" . PHP_EOL .
"Reply-To: $email" . PHP_EOL .
"Business: $subject" . PHP_EOL .
"Website: $business_site" . PHP_EOL .
"Average Monthly Volume: $avgvolume" . PHP_EOL .
"Preferred Contact Method: $contactmethod" . PHP_EOL .
"Business Description: $message" . PHP_EOL .
"X-Mailer: PHP/" . phpversion()
);
if( $sendemail ) {
echo 'OK';
} else {
echo 'Could not send mail! Please check your PHP mail configuration.';
}
}
?>

PHP Contact form empty body (bootstrap)

I am having trouble with my contact form (from bootstrap). the php code as well as the html code are as seen below. Whenever I try the contact form, the body will be empty. Am I missing anything?
This is the html code:
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input type="text" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input type="text" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input type="text" class="input-block-level" required="required" placeholder="Your email address">
</div>
<div class="span7">
<label>Message</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>
</form>
This is the PHP code:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'mail#luckystarmaids.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Your name and email form elements don't have name attributes. Without them, they won't be posted to the form's action1, 2.
Add names to your inputs:
<input type="text" name="first_name" class="input-block-level" required="required" placeholder="Your Last Name">
Also you will need to handle first and last name in your PHP code, at the moment you're only looking for name.
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input name=firstname type="text" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input name=lastname type="text" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input name=email type="text" class="input-block-level" required="required" placeholder="Your email address">
<label>Subject</label>
<input name=subject type="text" class="input-block-level" required="required" placeholder="Subject">
</div>
<div class="span7">
<label>Message</label>
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
<p> </p>
</form>
Try also to handle the data on the server. Check at least if the values are send:
<?php
if ( isset( $_POST['firstname'] )
&& isset( $_POST['email'] )
&& isset( $_POST['subject'] )
&& isset( $_POST['message'] ) )
{
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'mail#luckystarmaids.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $s
ubject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
if ($success)
{
echo json_encode(array(
'success'=> true,
'message'=>'Email sent, you recieve an email at ' . $email
));
}
}
else
{
echo json_encode(array(
'success' => false,
'message' => 'An error has occured, please try again.'
));
}
?>

Can't seem to get PHP form to display

I am working on my version 2 of my portfolio site, I had a working mailer I created with a guide about a year ago, transferred it, and can't get my page to display now.
Here is the code I am using:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo <form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
}
?>
I ran it through a PHP syntax checker and it did not pull anything out, does anyone have any ideas?
For reference: Here is the original code I used on Version 1. I formatted it so it would display the email a little more cleaner, which probably royally screwed it up.
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My Portfolio Website"] ;
$message = $_REQUEST['message'].", Name: ".$name.", ".$phone.", Email: ".$email;
mail("TylerJStelmach#gmail.com", $subject, $message, "From:" . $email);
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo "<form method='post' action='index.php'>
<input type='text' input name='name' id='name' class='contacttext' placeholder=' Your Name' required>
<input type='text' input name='email' id='email' class='contacttext' placeholder=' Your Email Address' required>
<textarea input type='text' name='message' id='message' class='contacttext' placeholder=' Your Message' cols='55' rows='5' required></textarea>
<input type='submit' id='submit' class='submitcontacttext' value='Send Message'>
</form>";
}
?>
There are some syntax errors.
Also, your snipplet does not contain code to send mail.
Corrected code is as following:
<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
//if "email" is not filled out, display the form
echo '<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>';
}
?>
as all are saying where is the line to send mail but as i have seen your site there is no sign of any code.
as i am just guessing, even if the if is false, the else should run as it is running in my localhost.
the problem must be something with your sever.
put a error_reporting(E_ALL); on top it will show errors if it there.
else try writing in a new file.
<?php
error_reporting(E_ALL);
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$subject = $_REQUEST["My_Portfolio_Website"] ;
$message = $_REQUEST['message'] . "\nName: " . $name . "\nEmail: ".$email; "\n \nMessage: ".$message;
echo "<h1>Thank you for contacting me. I will get back to you ASAP!</h1>";
}else{
?>
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<div class="metro-button" type="submit">Click me</div>
</div>
</form>
<?php
}
?>
I was able to figure this out by re-writing the original code I had based on the guide I used about a year ago, I came up with this for the answer which indeed works.
For all of the handling of where the information goes and how it was formated I included this chunk of php before I declared the doctype.
<?php
if($_POST["submit"]) {
$recipient="myemail#email.com";
$subject="Client Mail";
$name=$_POST["name"];
$email=$_POST["email"];
$email_from = $_POST['email'];
$message=$_POST["message"];
$mailBody="Name: $name\nEmail: $email\n\nMessage: $message";
mail($recipient, $subject, $mailBody, "From: $sender <$email>");
$thankYou="<p class='thank-you'>Thank you! Your message has been sent.</p>";
}
?>
From here, I figured out that the reason it wasn't submitting to it's own page was because my submit button was neither a button or input. I had it set as a div so with some tweaks here and there I rewrote the lower half to include an input as the submit. Which left me with this:
<?=$thankYou ?>
I included a small amount of text to display ( the $thankYou ) when you submit to the page and it reloads.
<form method="post" action="contact.php" class="connect">
<div>
<input id="name" name="name" type="text" required>
<label for="name">Your Name</label>
</div>
<div>
<input id="email" name="email" type="text" required>
<label for="email">Your Email</label>
</div>
<div>
<textarea id="message" name="message" required></textarea>
<label for="message">Your Message</label>
</div>
<div class="metro">
<input type="submit" name="submit" class="metro-button submit-me">
</div>
</form>
So now when submitted, the email comes in with:
The 'from' being set by $email
The 'subject' being set by $subject
and the message ($message) being formatted in this manner:
Name: John Doe
Email: JDoe#fake.com
Message: This is John Doe's message.
My apologies for the terrible question phrasing before hand, it was late at night and I was getting frustrated and losing my place, got a good nights rest and was able to solve it.
Here is the live version, I encourage you to test it, it works for me perfectly, hopefully this snippet can help someone else in the future!

Contact Form fields not being passed

I am working on a simple contact form however when the email comes through the fields are empty. The form sends fine but it doesn't get any of the values. My form HTML looks like this.
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">
<input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">
<input type="text" name="email" id="email" class="input-block-level" required="required" placeholder="Your email address">
<textarea name="message" id="message" required="required" class="input-block-level" rows="8"></textarea>
<button type="submit" class="btn btn-primary btn-large pull-right">Send Message</button>
The PHP side of things is as follows
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$nameFirst = $_POST['namefirst'];
$nameLast = $_POST['namelast'];
$email = $_POST['email'];
$message = $_POST['message'];
$subject = $message;
$email_from = $email;
$email_to = 'jdwman14#gmail.com';
$body = 'Name: ' . $nameFirst .' '. $nameLast. "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
When the email comes through it has this format but has none of the variables.
Name:
Email:
Subject:
Message:
There is issue in Form,
There are two time namefirst input field in your form
<input type="text" name="namefirst" id="namefirst" class="input-block-level" required="required" placeholder="Your First Name">
replace namefirst with lastname in name & id attribute value in second input as following,
<input type="text" name="namelast" id="namelast" class="input-block-level" required="required" placeholder="Your Last Name">
I hope this solve your issue...

Categories