Here's my HTML code:
<form method="POST" action="thank_you.php" novalidate>
<div class="form-group">
<label for="name">Full Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name" required>
<div class="valid-feedback">Looks good</div>
<div class="invalid-feedback">Please enter your name</div>
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="eg: email#email.com" required>
</div>
<div class="form-group">
<label for="url">Your Website</label>
<input type="text" class="form-control" id="url" name="url" placeholder="eg: www.website.com">
</div>
<h4>Project Details</h4>
<p>Please provide a brief description of your project, what your end goal is, and how I can help you achieve this goal.
Please, also specify what your budget is.</p>
<div class="form-group">
<label for="budget">Budget Amount</label>
<input type="text" class="form-control" id="budget" name="budget" placeholder="eg: $2,000" required>
</div>
<div class="form-group">
<label for="project">Project Description</label>
<textarea class="form-control" id="project" name="project" rows="5" required></textarea>
</div>
<div class="form-group">
<label for="completion">Desired Completion Date</label>
<select class="form-control" id="completion" name="completion" required>
<option>Please select</option>
<option>As soon as possible</option>
<option>1-3 weeks</option>
<option>1-3 months</option>
<option>4-6 months</option>
<option>To be determined</option>
</select>
</div>
<button type="submit" class="btn btn-primary" name="submit">SEND</button>
</form>
And here's my PHP:
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$to = "jb#jbwebsitesolutions.com";
$subject = "New Request";
$body = "Please see details below.";
mail($to, $subject, $body);
?>
What happens is once the form is submitted, only everything in the mail(function) displays, but not the input one. So Can somebody please show me where I went wrong and how I can fix it?
Currently your code is incomplete, You should include the submission data to $body
like this:
$body = "Please see details below.";
$body .= '\r\n Name :'.$name.'\r\n';
$body .= '\r\n Email :'.$email.'\r\n';
also the option tag must have a value attribute
<select class="form-control" id="completion" name="completion" required>
<option value="">Please select</option>
<option value="As soon as possible">As soon as possible</option>
<option value="1-3 weeks">1-3 weeks</option>
<option value="1-3 months">1-3 months</option>
<option value="4-6 months">4-6 months</option>
<option value="To be determined">To be determined</option>
</select>
You have to pass POST data into $body tag for example :
$to = "jb#jbwebsitesolutions.com";
$subject = "New Request";
$body = "";
$name = $_POST['name'];
$email = $_POST['email'];
$url = $_POST['url'];
$budget = $_POST['budget'];
$project = $_POST['project'];
$completion = $_POST['completion'];
$body = "Hello ". $name."," .'<br/>';
$body .= $email;
$body .= "Your bugdet is :" . $budget;
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$body,$headers);
Related
I am creating a business website having a form.. Currently my form details are sent to email.. I want that when form is submitted the details should be added in google sheet directly. because it is hard to check every mail. plz help.
HTML
<form method="post" name="contact_form" name="myForm" id="myForm" action="sendmail.php">
<div class="col-md-12">
<div class="form-group">
<input type="text" name="name" class="form-control" id="name" placeholder="Name*" required />
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<input type="text" name="phone" class="form-control" id="phone" placeholder="Mobile No.*" required pattern="[0-9]{3}[0-9]{3}[0-9]{4}">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<button type="" name="submit">Submit</button>
</div>
</div>
<div class="clear"></div>
</form>
pHp
<?PHP
$name = $_POST["name"];
//$lname = $_POST["lname"];
$phone = $_POST["phone"];
$to = "yourmail#gmail.com";
$subject = "New Email Address for project";
$headers = "From: $name\n";
$message = "This form has been submitted to project.\n
Name : $name;
Mobile No. : $phone";
mail($to,$subject,$message,$headers);
header('Location: http://websites.com/thank_you.html');
$thank_you = "Thank You For your interest. <br>We will Contact you soon";
echo "$thank_you .";
?>
I have a PHP form (Wilio - Survey and Multipurpose Form Wizard) send emails to submitter and admin, it's not connected with a database, my aim is once the user submits his data, the form sends it directly by mail as a word attachment without any more steps.
here is the HTML code
<form id="wrapped" method="POST">
<input id="website" name="website" type="text" value="">
<div id="middle-wizard">
<div class="step">
<h3 class="main_question"><strong>1/2</strong>Please fill the below</h3>
<div class="form-group">
<input type="text" name="student_name" class="form-control required" placeholder="Student Name" onchange="getVals(this, 'student_name');">
</div>
<div class="form-group">
<input type="text" name="school_name" class="form-control required" placeholder="School Name" onchange="getVals(this, 'school_name');">
</div>
<div class="form-group">
<input type="text" name="teacher_name" class="form-control required" placeholder="Teacher Name" onchange="getVals(this, 'teacher_name');">
</div>
<div class="form-group">
<input type="text" name="class_name" class="form-control required" placeholder="Class" onchange="getVals(this, 'class_name');">
</div>
<div class="form-group">
<input type="email" name="email" class="form-control required" placeholder="Your Email" onchange="getVals(this, 'email');">
</div>
<div class="form-group">
<input type="number" name="mobile_number" class="form-control required" placeholder="Mobile Number" onchange="getVals(this, 'mobile_number');">
</div>
</div>
<div class="submit step">
<h3 class="main_question"><strong>2/2</strong>Summary</h3>
<div class="summary">
<ul>
<li><strong>1</strong>
<h5>Personal Details</h5>
<ul>
<li><label>Student Name</label>: <span id="student_name"></span></li>
<li><label>Mobile Number</label>: <span id="mobile_number"></span></li>
<li><label>Email</label>: <span id="email"></span></li>
</ul>
</li>
<li><strong>2</strong>
<h5>Educational Details</h5>
<ul>
<li><label>School Name</label>: <span id="school_name"></span></li>
<li><label>Teacher Name</label>: <span id="teacher_name"></span></li>
<li><label>Class</label>: <span id="class_name"></span></li>
</ul>
</li>
</ul>
</div>
</div>
</div>
<div id="bottom-wizard">
<button type="button" name="backward" class="backward">Prev</button>
<button type="button" name="forward" class="forward">Next</button>
<button type="submit" name="process" class="submit">Submit</button>
</div>
</form>
and here is the PHP Code
<?php
$mail = $_POST['email'];
$to = "my-email#my-domain.com";
$subject = "Appreciation Certificate";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Education Council <noreply#my-domain.com>";
$message .= '<div style="text-align: center;"><img src="http://www.my-domain.com/testmail/html/img/banner.jpg" alt="Education Council Banner" /></div>';
$message .= "<h1 style='text-align: center;'>Appreciation Certificate</h1>";
$message .= "\n\n<h2 style='text-align: center;'>World Teachers Day</h2>";
$message .= "\n\n<h1 style='text-align: center;'>It's good to appreciate others for their excellence, efforts and giving</h1>";
$message .= "\n\n<h1 style='text-align: center;'>Student: </h1>" . $_POST['student_name'];
$message .= "\n\n<h1 style='text-align: center;'>School: </h1>" . $_POST['school_name'];
$message .= "\n\n<h1 style='text-align: center;'>My thanks and gratitude to my teacher</h1>";
$message .= $_POST['teacher_name'];
$message .= "\n\n<h1 style='text-align: center;'>On the occasion of World Teachers Day 2019</h1>";
$message .= "\n\n<h2 style='text-align: center;'>Hoping for them permanence excellence and giving</h2>";
$message .= "\n\n<h2 style='text-align: center;'>The Education Council</h2>";
//Receive Variable
$sentOk = mail($to,$subject,$message,$headers);
//Confirmation page
$user = "$mail";
$usersubject = "Appreciation Certificate";
$userheaders .= 'MIME-Version: 1.0' . "\r\n";
$userheaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$userheaders .= "From: Education Council <noreply#my-domain.com>\n";
$usermessage = "$message";
mail($user,$usersubject,$usermessage,$userheaders,$headers);
?>
hope to find a help.
As an intermediate web developer, I have a problem with my form not send inserted data(the email goes through but form data does not), I don't know if it is form or PHP script.
HTML
<form id="main-contact-form" name="contact-form" method="POST" action="sendemail.php">
<fieldset>
<div class="row wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<div class="col-sm-6">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" class="form-control" placeholder="Subject" required="required">
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" placeholder="Enter your message" required="required"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn-submit">Send Now</button>
</div>
</fieldset>
</form>
JS
// Contact form
var form = $('#main-contact-form');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div class="form_status"></div>');
$.ajax({
url: $(this).attr('action'),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p class="text-success">Thank you for contacting us. We will respond to you as soon as possible</p>').delay(5000).fadeOut();
});
});
PHP
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = 'email#email.com';
$headers .= "MIME-Version: 1.0";
$headers .= "Content-type: text/plain; charset=iso-8859-1";
$headers .= "From: {$name} <{$from}>";
$headers .= "Reply-To: <{$from}>";
$headers .= "Subject: {$subject}";
$headers .= "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);die;
?>
Please help as I am stuch here.
#trim(stripslashes($_POST['name']));
Using # to suppress errors and warnings is generally considered to be a bad idea at the best of times. Doing it when you are trying to debug a problem is an exceptionally bad idea.
form.submit(function(event){
event.preventDefault();
You use JavaScript to prevent your form from submitting.
$.ajax({
url: $(this).attr('action'),
beforeSend: function(){
form.prepend( form_status.html('<p><i class="fa fa-spinner fa-spin"></i> Email is sending...</p>').fadeIn() );
}
Then you use JavaScript to make an HTTP request instead.
You set the URL to be the same as the form.
You don't send any data.
You don't set the method (so it defaults to GET).
If you want to send data from your JavaScript, then you have to actually send it.
The jQuery tutorial explains how to read form data. Don't forget to set the method too.
I'm trying to keep textbox, select option and textarea values, after submit form without clicking on the reCAPTCHA box. It will keep the textbox, select option and textarea as i wish. but when the textarea has line breaks it will not appear text in the textarea.
php
<?php
session_start();
if(isset($_POST['submit'])){
if(isset($_POST['g-recaptcha-response'])){
//your site secret key
$secret = 'site secret key';
//get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
//contact form submission code
$name = $_POST['username'];
$replyto = $_POST['emailadd'];
$subject = $_POST['selectOption'];
$message = nl2br($_POST['message']);
$_SESSION['username'] = $name;
$_SESSION['replyto'] = $replyto;
$_SESSION['subject'] = $subject;
$_SESSION['message'] = $message;
if($responseData->success){
$email = "info#email.com";
$to = "info#email.com";
$headers = 'From:'.$name.' <'.$email.'>'."\r\n".'Reply-To:'.$replyto. "\r\n".'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$headers);
$succMsg = 'Your contact request have submitted successfully.';
session_destroy();
echo "<script type='text/javascript'>alert('$succMsg'); window.location = '/'; </script>";
}
else{
$flag = 1;
echo "<script type='text/javascript'>window.location = '#contactus';</script>";
}
}
else{
$flag = 1;
echo "<script type='text/javascript'>window.location = '#contactDiv';</script>";
}
}?>
< script type = "text/javascript" >
$(document).ready(function() {
$("#errorcaptcha").hide();
var flag = '<?php echo $flag; ?>';
var usernmae = "<?php if(isset($_SESSION['username'])){echo $_SESSION['username'];} ?>";//working fine
var email = "<?php if(isset($_SESSION['replyto'])){echo $_SESSION['replyto'];} ?>";//working fine
var subject = "<?php if(isset($_SESSION['subject'])){echo $_SESSION['subject'];} ?>";//working fine
var message = "<?php if(isset($_SESSION['message'])){echo $_SESSION['message'];} ?>"; //error here, works when without line breaks text
if (flag == 1) {
$("#errorcaptcha").show();
$('#username').val(usernmae);
$('#emailadd').val(email);
$('#selectOption').val(subject);
$('#message').val(message);
}
}); < /script>
<!DOCTYPE html>
<html lang="en">
<body id="page-top">
<form id="contactfrom" method="post">
<div class="form-group">
<div class="col-sm-12">
<input class="form-control" name="username" id="username" maxlength="40" required="required" type="text" placeholder="Your name" value="" /> </div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input class="form-control" id="emailadd" name="emailadd" required="required" type="email" maxlength="50" placeholder="Your email" />
</div>
</div>
<label for="username" class="uname" data-icon="u">Inquiry about</label>
<div class="form-group">
<div class="col-sm-12">
<select name="selectOption" id="selectOption" class="form-control">
<option value="1" selected="">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<textarea maxlength="500" id="message" name="message" placeholder="Massage" class="form-control" rows="5" required="required"></textarea>
</div>
</div>
<div>
</div>
<div class="form-group">
<div class="col-sm-12">
<label id="errorcaptcha" for="">Please click on the reCAPTCHA box.</label>
</div>
</div>
<div class="form-group">
<div class="col-sm-12" id="recaptcha">
<div class="g-recaptcha" data-theme="dark" data-sitekey="sitekey"></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<button type="submit" name="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
</body>
Store in session you original $_POST['message']:
Replace
$message = nl2br($_POST['message']);
with
$message = $_POST['message'];
Then after format for your e-mail with nl2br:
mail($to,$subject,nl2br($message),$headers);
Finally i found my own way. textarea doesn't have a value. helpful link here
<textarea maxlength="500" id="message" type="text" name="message" placeholder="Massage" class="form-control" rows="5" required="required"><?php echo isset($_POST['message']) ? htmlspecialchars($_POST['message']):'' ?></textarea>
Hope this kind of questions are answered lot many times but I have went through most of them and din't found any solution please help to solve my problem.
I had a html form
<form id="main-contact-form" class="contact-form" enctype="text/plain" 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="vname" id="vname" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="vemail" id="vemail" class="form-control" required="required">
</div>
<div class="form-group">
<label>Phone</label>
<input type="text" 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="vsubject" id="vsubject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Message *</label>
<textarea name="vmessage" 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>
and here is my php code for sending email
<?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['vname']));
$email = #trim(stripslashes($_POST['vemail']));
$subject = #trim(stripslashes($_POST['vsubject']));
$message = #trim(stripslashes($_POST['vmessage']));
$email_from = $email;
$email_to = 'myemail';//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();
Giving data and clicking on submit sending the emails but receiving blank data
Name:
Email:
Subject:
Message:
(unknown sender)
(no subject) - Name: Email: Subject: Message:
please help as I am very new to PHP
I am using CENTOS web panel with Apache