This is a contact form, when I click on submit button I am receiving the mail but form values are not fetched. I am unable to find the problem. Can someone help me?
here i include my code:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['fn']));
$email = #trim(stripslashes($_POST['ln']));
$subject = #trim(stripslashes($_POST['email']));
$message = #trim(stripslashes($_POST['message']));
$sub = 'mail from xxxx.com';
$email_from = $subject;
$email_to = 'xxxx#gmail.com';
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $sub, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
?>
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post"">
<div class="row-fluid">
<div class="span5">
<label>First Name</label>
<input type="text" name="fn" class="input-block-level" required="required" placeholder="Your First Name">
<label>Last Name</label>
<input type="text" name="ln" class="input-block-level" required="required" placeholder="Your Last Name">
<label>Email Address</label>
<input type="text" name="email" 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>
<input type="submit" >
<p> </p>
</form>
I can solve this problem with silly mistake....
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post"">
in this line i can give so changes is
<form id="main-contact-form" class="contact-form" name="contact-form" action="send.php" method="post">
Related
I want to send an email with PHP when a user has finished filling in an HTML form and then emailing information from the form. I have below code but was not getting form values in mail. Can someone help me regarding this?
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-5">
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="First Name" name="name">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Last Name" name="lname">
</div>
<div class="form-group">
<input type="text" class="form-control" required="required" placeholder="Email address" name="email">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg" name="submit">Send Message</button>
</div>
</div>
<div class="col-sm-7">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
</div>
</form>
**sendemail.php**
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Email sent!'
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = "Mail from your website";
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'manish22it#gmail.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;
?>
I have a email form Here and am invoking the mail() function. for some reason I am not receiving any emails to my email account. My only guess is that it could be some config on the server
Here is my php script:
<?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 = 'keilcarpenter01#gmail.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;
And the html form:
<h1>Contact Form</h1>
<p>Send me a message and I will get back to you!</p>
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php" role="form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" required="required" placeholder="Name">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="email" class="form-control" required="required" placeholder="Email address">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="Message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger btn-lg">Send Message</button>
</div>
</div>
</div>
</form>
Could it be some config on the remote host or something wrong on my end?
I read that if your sending from localhost then you need to config the php.ini and sendmail.ini so I know that is out of the question.
Would PHPMailer be better to use?
I have a form with 3 input fields , the below field is not working as expected , post data is not being posted , remaining two input fields are working correctly
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php?m=std">
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php?m=std">
<div class="col-sm-10 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Doing graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="dngclgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="dngclgplace" class="form-control">
</div>
<div class="form-group">
<label>Completing in</label>
<input type="text" name="dngcomp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Completed Graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="clgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="clgplace" class="form-control">
</div>
<div class="form-group">
<label>Year of completion</label>
<input type="text" name="comp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Post Graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="pgclgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="pgclgplace" class="form-control">
</div>
<div class="form-group">
<label>Year of completion</label>
<input type="text" name="pgcomp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Working</h4>
<div class="form-group">
<label>Name of Company</label>
<input type="text" name="companyname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="companyplace" class="form-control">
</div>
<div class="form-group">
<label>Working since</label>
<input type="text" name="companywrk" class="form-control">
</div>
<div class="form-group">
<label>Total no of years of experience</label>
<input type="text" name="companyexp" class="form-control">
</div>
</div>
<div class="col-sm-10 col-sm-offset-1">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Your Message/ Query/ Information required *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
this is a part of my php code
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contacting us. As early as possible we will contact you '
);
// some code here (if condition, check if user has input other form , if user input this form everything is fine)
elseif($m == 'std'){
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$dngclgname = trim(stripslashes($_POST['dngclgname']));
$dngclgplace = trim(stripslashes($_POST['dngclgplace']));
$dngcomp = trim(stripslashes($_POST['dngcomp']));
$clgname = trim(stripslashes($_POST['clgname']));
$clgplace = trim(stripslashes($_POST['clgplace']));
$comp = trim(stripslashes($_POST['comp']));
$pgclgname = trim(stripslashes($_POST['pgclgname']));
$pgclgplace = trim(stripslashes($_POST['pgclgplace']));
$pgcomp = trim(stripslashes($_POST['pgcomp']));
$companyname = trim(stripslashes($_POST['companyname']));
$companyplace = trim(stripslashes($_POST['companyplace']));
$companywrk = trim(stripslashes($_POST['companywrk']));
$companyexp = trim(stripslashes($_POST['companyexp']));
$email_from = $email;
$email_to = 'my email address';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'graduating college name: ' . $dngclgname . "\n\n" . 'graduating college Place: ' . $dngclgplace . "\n\n" . 'graduation completion year: ' . $dngcomp . "\n\n" . ' graduated College name: ' . $clgname . "\n\n" . ' graduated College Place: ' . $clgplace . "\n\n" . ' Graduated Year: ' . $comp . "\n\n" . 'Post Graduation College name: ' . $pgclgname . "\n\n" . 'Post Graduation College Place: ' . $pgclgplace . "\n\n" . 'Post Graduation Completion/completed year: ' . $pgcomp . "\n\n" . 'Company name: ' . $companyname . "\n\n" . ' Company place: ' . $companyplace . "\n\n" . 'Working since : ' . $companywrk . "\n\n" . 'Total no of years of experience : ' . $companyexp . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
}
When i click on submit am getting redirecting to the correct url and even mail is coming to my address but all the user input fiels are empty in the mail , even from address in the mail is also empty ,
You should debug your code with var_dump($_POST).
You will see if all input value works.
When i've tried your code, everything worked well.
I have a contact form using php however when I test the form I receive an email with no content in the fields, I have checked that the fields match with the php but cannot seem to identify the problem.
The form html part of the contact page:
<section id="contact-page">
<div class="container">
<div class="center">
<h2>Send us a Message</h2>
<p class="lead">Thanks for your enquiry we will respond within 24 hours. * Indicates required information</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required>
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" name="tel"class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" name="company" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required>
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The Php script:
<?php
header('Content-type: application/json');
$status = array(
//'type'=>'success',
//'message'=>
'Thank you for contacting us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST["name"]));
$email = #trim(stripslashes($_POST["email"]));
$subject = #trim(stripslashes($_POST["subject"]));
$tel = #trim(stripslashes($_POST["tel"]));
$company = #trim(stripslashes($_POST["company"]));
$message = #trim(stripslashes($_POST["message"]));
$email_from = $email;
$email_to = 'xxx#xxx.com';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Phone Number: ' . $tel . "\n\n" .'Company Name : ' . $company . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Any help would be appreciated.
Thanks
or use
<form method="post" id="main-contact-form" class="contact-form" name="contact-form" >
in place of
<form action="sendemail2.php" method="post" id="main-contact-form" class="contact-form" name="contact-form" >
This bootstrap using html/php contact form sends me an email just fine, but without any of the users input information!
The email I received looks empty like this:
Name:
Email:
Subject:
Message:
The html for the form is:
<section id="partner">
<div class="container">
<div class="center wow fadeInDown">
<h2><br>Contact</h2>
<p class="lead">Send a general enquiry here or order your service here.</p>
</div>
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php">
<div class="col-sm-5 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="number" class="form-control">
</div>
<div class="form-group">
<label>Company Name</label>
<input type="text" class="form-control">
</div>
</div>
<div class="col-sm-5">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
</div><!--/.container-->
</section><!--/#contact-page-->
The PHP for the form looks like this:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$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 = 'heerschapnikki#gmail.com';//replace with your email
$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;
Why isn't it working properly? The message "thank you for contacting us" pops up fine and the email sends through, but non of the users information comes through.
Try to print the values you are sending. So use this:
var_dump( $_POST['name'] );
var_dump( $_POST['email'] );
etc...
Doing this, you will be able to see wether your fields are even posted correctly.
the fields have no id param. in the post you get the "id" nor the "name"
<label>Name *</label>
<input type="text" id="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" id="email" class="form-control" required="required">