Form to Email PHP - php

Hi I am new to php and am not quite sure how to do this I am attempting to build a contact form that sends an email currently the HTML I Have for the form is:
<section class="mbr-section form1 cid-qL6aon4aVW" id="form1-11">
<div class="container">
<div class="row justify-content-center">
<div class="title col-12 col-lg-8">
<h2 class="mbr-section-title align-center pb-3 mbr-fonts-style display-2">
MAINTENANCE FORM
</h2>
<h3 class="mbr-section-subtitle align-center mbr-light pb-3 mbr-fonts-style display-5">
Request Maintenance for your unit.</h3>
</div>
</div>
</div>
<div class="container">
<div class="row justify-content-center">
<div class="media-container-column col-lg-8" data-form-type="formoid">
<form class="mbr-form" action="feedback.php" method="post">
<div class="row row-sm-offset">
<div class="col-md-4 multi-horizontal" data-for="name">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="name-form1-11">Full Name</label>
<input type="text" class="form-control" name="name" data-form-field="Name" required="" placeholder="Full Name" id="name-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="email">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="email-form1-11">Email Address</label>
<input type="email" class="form-control" name="email" data-form-field="Email" required="" placeholder="Email" id="email-form1-11">
</div>
</div>
<div class="col-md-4 multi-horizontal" data-for="phone">
<div class="form-group">
<label class="form-control-label mbr-fonts-style display-7" for="phone-form1-11">Phone Number</label>
<input type="tel" class="form-control" name="phone" data-form-field="Phone" placeholder="Phone #" id="phone-form1-11">
</div>
</div>
</div>
<div class="form-group" data-for="message">
<label class="form-control-label mbr-fonts-style display-7" for="message-form1-11">Request</label>
<textarea type="text" class="form-control" name="message" rows="7" data-form-field="Message" placeholder="Request" id="message-form1-11"></textarea>
</div>
<span class="input-group-btn">
<button href="" type="submit" class="btn btn-primary btn-form display-4">SEND FORM</button>
</span>
</form>
</div>
</div>
</div>
And the PHP I have is :
<?php
if (isset($_POST['submit'])){
$to="email#email.com";
$subject="Shovers.net Maintenance form submission";
$mail_from="from: ".$_POST['email']." \n";
$mail_from .="Content-Type: text/html; charset=utf-8 \n";
$message="<font size=\"2\" face=\"Verdana\"> Here is the message:<br />
".$_POST['comments']."<br />
".$_POST['name']."<br />
".$_POST['email']."</font>";
mail($mail_from,$to,$subject,$comments);
echo "Thanks!";
$TARGET = "/";
header("Location: $TARGET");
exit();
}else{
}
?>
I can't seem to get this to send to my email and I am not sure why on form submit it currently just goes to the feedback.php page which is blank as it is just the PHP script. Does this need to be running on the actual server for it to work or will it work with xampp and apache/mysql running? If not what do I need to do to get this working?
In addition I am also trying to get it to just reload/stay on that same page but pop up a verification message what am I doing wrong for that?
Any help appreciated!
Thanks!

Related

Why is my form validation not getting set in codeigniter

im trying to create a templated system with CI. So far everything is working flawlessly and im testing out form validation but its not working at all. As you can see from the code below there are both html5 required statements as well as the codeigniter rules. Neither of which are working after I hit the submit button. So i'm not sure whats going wrong. Something stupid im sure.
public function show_form(){
$form_data = '<div class="row">
<div class="col-md-12">
<div class="card-box">
<h4 class="m-t-0 header-title"><b>Basic Form Wizard</b></h4>
<form id="basic-form" action="#">
<div>
<h3>Account</h3>
<section>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="username">User name *</label>
<div class="col-lg-10">
<input class="form-control" id="username" name="username" type="text">
</div>
</div>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="password"> Password *</label>
<div class="col-lg-10">
<input id="password" name="password" type="text" class="required form-control">
</div>
</div>
<div class="form-group clearfix">
<label class="col-lg-2 control-label " for="confirm">Confirm Password *</label>
<div class="col-lg-10">
<input id="confirm" name="confirm" type="text" class="required form-control">
</div>
</div>
</section>
<input type="submit" value="Submit" />
</div>
</form>
</div>
</div>
</div>';
$this->CI->form_validation->set_rules('username', 'Username', 'required');
if ( $this->CI->form_validation->run() == FALSE ):
echo "<pre>Before Validation</pre>";
echo validation_errors();
echo "<pre>After Validation</pre>";
echo $form_data;
else:
echo "We did it";
endif;
}
Thanks in advance for any guidance.

send email through php

First time here for me
I have 2 files (index.html , sendemail.php)
At index.html I have the code for my form
<section id="contact">
<div id="contact-us" class="parallax">
<div class="container">
<div class="row">
<div class="heading text-center col-sm-8 col-sm-offset-2 wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<h2>Contact Us</h2>
<p>Request a service , learn about our services</p>
</div>
</div>
<div class="contact-form wow fadeIn" data-wow-duration="1000ms" data-wow-delay="600ms">
<div class="row">
<div class="col-sm-6">
<form id="main-contact-form" name="contact-form" method="post" enctype="multipart/form-data" action="sendemail.php">
<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" id="name" class="form-control" placeholder="Name" required="required">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input type="email" name="email" id="email" class="form-control" placeholder="Email Address" required="required">
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="subject" id="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" name="submit" id="submit">Send Now</button>
</div>
</form>
</div>
<div class="col-sm-6">
<div class="contact-info wow fadeInUp" data-wow-duration="1000ms" data-wow-delay="300ms">
<p></p>
<ul class="address">
<li><i class="fa fa-phone"></i> <span> Phone:</span> +30 6982 215487 </li>
<li><i class="fa fa-envelope"></i> <span> Email:</span> info#mydomain.com</li>
<li><i class="fa fa-globe"></i> <span> Website:</span> www.mydomain.com</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
At sendemail.php I have the code
$msg = 'Name: ' .$_POST['name'] ."\n"
.'Email :' .$_POST['email'] ."\n"
.'Subject: ' .$_POST['subject'] ."\n"
.'Message: ' .$_POST['message'] ."\n";
mail('info#mydomain.com','You have one message from mydomain.com', $msg);
I get an email when i send this form but with no values into it like this
Name:
Email :
Subject:
Message:
Where is the problem with this code ?
Thanks
try change enctype in your form tag
<form id="main-contact-form" name="contact-form" method="post" enctype="application/x-www-form-urlencoded" action="sendemail.php">
also, you can print post data:
print(file_get_contents('php://input'));
If you are working on local then
you have to use library to send mail such as PHPMailer.
Check your firewall settings blocking or what.
Check any other service is using the ports (25,465,587).
If you are working on Live then
check your hosting provider allowing you to send mail.
(for this you can send test mail script directly using mail function)
If you are using library then you have to confirm with hosting
provider that they allow ports opened for send mail.

Web site send message

When i post a Message from my web page it returns a ? in the browser such as this,
I believe both the HTML and the php to be correct
The html......
`enter code here`
<form class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</section>
enter code here
you have declare form method and its action in form tag. Something like as follows
<form action="actionPage.php" method="POST"> //you can send data in get method or post method
Hope this will work for you...
action="yourLoctionUrl" tell the form where to submit data.
if you will do it empty then it will show ?yourinput fields&other inputs
<form action="sendcontact.php" method="post" class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
You have used form tag twice in your coding. put your action and post in starting form tag as i did.
You didn't close the second form tag. Go for this:
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</form>

php form not sending submission data. sending email and processing form still however

I Have two forms on my site. One works fine and the other sends email with email_from: etc but doesn't capture any of the form data.
Wondering what it may be. I can post the form that is working along with it's html too if that would help debug. Very much a novice and built form using stack overflow/other sites.
Coffee
<div class="form-group">
<label class="col-sm-3 control-label">Quantity</label>
<div class="col-sm-4">
<input type="text" name="quantity" class="form-control" placeholder="Quantity : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" name="name" class="form-control" placeholder="Name : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email address</label>
<div class="col-sm-6">
<input type="email" name="email" class="form-control" placeholder="Email address : " required>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Shipping Address</label>
<div class="col-sm-6">
<textarea class="form-control" name="shipping_address" rows="8" placeholder="Shipping Address : " required></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Payment Method</label>
<div class="col-sm-6">
<select class="form-control" required>
<option value="Paypal">Paypal</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Notes</label>
<div class="col-sm-6">
<textarea class="form-control" name="notes" rows="8" placeholder="Notes : "></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-10">
<button type="submit" class="btn btn-black">Order Now</button></a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
And here is the php
<?php
if(isset($_POST ['submit']))
{
$coffee = ($_POST['coffee']));
$quantity = ($_POST['quantity']));
$name = ($_POST['name']));
$email = ($_POST['email']));
$shipping_address = ($_POST['shipping_address']));
$notes = ($_POST['notes']));
}
$email_from ='paradigmcoffee#gmail.com';
$email_subject="New Order Submission";
$email_body ="You have received a new message from user $name.\n".
"Email_address:$email\n".
"Coffee: $coffee\n".
"Quantity: $quantity\n".
"Shipping_Address: $shipping_address\n".
"Notes: $notes\n".
$to ="paradigmcoffee#gmail.com";
$headers = "From: $email \r\n";
mail($to,$email_from,$email_subject,$email_body,$headers);
header("Location: http://www.paradigmcoffee.co/order_thanks.html");
?>
From what you have supplied, likely the reason you can not get data is because you are not sending anything called submit. Try naming your button:
<!-- name="submit" added -->
<button name="submit" type="submit" class="btn btn-black">Order Now</button>
You can do this or make a hidden field:
<input type="hidden" name="submit" value="1" />

Bootstrap HTML form, MySQL query result

I'm in the process of migrating a Drupal build out to Bootstrap framework. In the new Bootstrap framework, I've built out a form to pull results from a database.
Bootstrap form HTML:
<form class="form-horizontal" role="form" method="post" action="<?php echo lookup_dosearchx() ?>">
<br>
<div class="form-group">
<label for="county2" class="col-sm-3 control-label">County:</label>
<div class="col-sm-6">
<input type="text" name="county2" id="county2" class="form-control" placeholder="Enter County Name" required />
</div>
</div>
<hr>
<center><i>Include Payroll Notes:</i></center><br>
<div class="form-group">
<label for="employee" class="col-sm-3 control-label">Employee:</label>
<div class="col-sm-6">
<select class="form-control" name="employee" id="employee" placeholder="Enter Employee Name" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<label for="startdate" class="col-sm-3 control-label">State Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="startdate" id="startdate" class="form-control" placeholder="Enter Start Date" />
</div>
</div>
<div class="form-group">
<label for="enddate" class="col-sm-3 control-label">End Date (mm/dd/yyyy):</label>
<div class="col-sm-6">
<input type="date" name="enddate" id="enddate" class="form-control" placeholder="Enter End Date" />
</div>
</div>
<div class="form-group">
<label for="fulltext" class="col-sm-3 control-label">Fulltext Query:</label>
<div class="col-sm-6">
<textarea class="form-control" name="fulltext" id="fulltext" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="contain" class="col-sm-3 control-label">Phrase:</label>
<div class="col-sm-6">
<textarea class="form-control" name="contain" id="contain" rows="4" /></textarea>
</div>
</div>
<div class="form-group">
<label for="jobid" class="col-sm-3 control-label">VCS Job Code:</label>
<div class="col-sm-6">
<select class="form-control" name="jobid" id="jobid" placeholder="Enter Job Code" /><option>Any</option></select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Clear</button>
</div>
</div>
</div>
<br>
</form>
I was provided with a large PHP query set from the prior build out, but that code isn't working when I hit submit. The database is connecting fine as I had trouble getting that to work before.
Would it be possible to be pointed in the direction of a simple example or recommended way to build out the PHP query code I'm calling out?

Categories