Php Bootstrap contact form not working, no email/data posted - php

I have a form in Bootstrap that's inside a modal. When I click the "Submit"
there is seems nothing happen,
I have checked the code for the typo and other errors and it seems nothing wrong with my php code but again every time I fill the form and hit the submit button the page is reloaded but email/data not posted
here is the complete php code :
<?php
if(isset($_POST['Submit'])){
$to = 'Support#example.com'; // this is your Email address
$from = $_POST['faq-contact-email'];// this is the sender's Email address
$first_name = $_POST['faq-contact-firstname'];
$last_name = $_POST['faq-contact-lastname'];
$division = $_POST['faq-contact-subject'];
$subject = $_POST['contact-subject'];
$themessage = $_POST['faq-contact-msg'];
$message = 'Support mail from : '.$first_name.' '.$last_name.'<br/>
To : '.$division.' Division<br/>
<hr/>
'.$themessage.'';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: ".$from."\r\n"."X-Mailer: php";
mail($to,$subject,$message,$headers);
echo "Support message Sent. Thank you " . $first_name . ", we will contact you shortly.";
}
?>
<div class="content">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#faq4" href="#faq4_q1"><i class="fa fa-envelope-o"></i> Contact Support</a>
</h3>
</div>
<div id="faq4_q1" class="panel-collapse collapse in">
<div class="panel-body">
<form method="post" action="" class="form-horizontal push-10-t" >
<div class="form-group">
<div class="col-xs-6 col-sm-4">
<div class="form-material form-material-primary">
<input class="form-control" type="text" id="faq-contact-firstname" name="faq-contact-firstname" placeholder="Enter your firstname..">
<label for="faq-contact-firstname">Firstname</label>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="form-material form-material-primary">
<input class="form-control" type="text" id="faq-contact-lastname" name="faq-contact-lastname" placeholder="Enter your lastname..">
<label for="faq-contact-lastname">Lastname</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-8">
<div class="form-material form-material-primary input-group">
<input class="form-control" type="email" id="faq-contact-email" name="faq-contact-email" placeholder="Enter your email..">
<label for="faq-contact-email">Email</label>
<span class="input-group-addon"><i class="fa fa-envelope-o"></i></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<div class="form-material form-material-primary">
<select class="form-control" id="faq-contact-subject" name="faq-contact-subject" size="1">
<option value="1">Tech Support</option>
<option value="2">Billing</option>
</select>
<label for="faq-contact-subject">Where?</label>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-4">
<div class="form-material form-material-primary">
<input class="form-control" type="text" id="contact-subject" name="contact-subject" placeholder="Enter your subject..">
<label for="contact-subject">Subject</label>
</div>
</div>
<div class="form-group">
<div class="col-xs-12">
<div class="form-material form-material-primary">
<textarea class="form-control" id="faq-contact-msg" name="faq-contact-msg" rows="7" placeholder="Enter your message.."></textarea>
<label for="faq-contact-msg">Message</label>
</div>
<div class="help-block text-right">Feel free to use common tags: <blockquote>, <strong>, <em></div>
</div>
</div>
<div class="form-group remove-margin-b">
<div class="col-xs-12">
<button class="btn btn-sm btn-primary" name="submit" type="submit"><i class="fa fa-send push-5-r"></i> Send Message</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
Can anyone please help me what's wrong with my code
If someone could help that would be greatly appreciated!
Thanks

Ok, I make an answer of my comment.
if(isset($_POST['Submit']))
Change Submit to submit. You can also use
if(isset($_POST))
instead

Check your first line
if(isset($_POST['Submit']))
You have written "Submit" (capital S) ,where the name of your button is "submit" . so make it
if(isset($_POST['submit']))

Related

ticket email not sending

Hi everyone i am struggling to fix my problem. I am trying to create a ticket system which a user can send a ticket and ask for help. The problem is that email is not working - it will not send any message after the user submit. I copied this codes on the internet and make some few changes of it
here's the code
new_ticket.php
<form action = "action_ticket.php" method="POST">
<div class="container mt-4">
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">Submit a ticket about your concern <span class="text-danger">Note: Please keep your ticket ID for security purposes</span></div>
<div class="card-body">
<div class="row">
<div class="col-12 col-md-6">
<div class="form-group">
<label>Your E-Mail Address <span class="text-danger">*</span></label>
<input type="email" required name="email" id="email" autocomplete = "off" placeholder="Your Email Address" class="form-control">
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-floating mb-3">
<select id="department" name="department" class="form-select">
<option value="" selected="selected" disabled="disabled">where you want so send this ticket</option>
</select>
<label for="floatingSelect">Select<span class="text-danger">*</span></label>
</div>
</div>
<div class="col-12 col-md-6">
<div class="form-group">
<label>Subject <span class="text-danger">*</span></label>
<input type="text" required name="subject" id="subject" autocomplete = "off" placeholder="Subject means your concern" class="form-control">
</div>
</div>
<div class="col-12">
<div class="form-group">
<textarea name="message" class="form-control" id="message" cols="30" rows="5" placeholder="Explain your concern here"></textarea>
</div>
</div>
<div class="col-12 col-md-12">
<div class="text-right">
<input type="hidden" name="submit" value="form">
<button class="btn btn-outline-primary" type="submit">Submit</button>
Back
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
and this is my other file
action_ticket.php
if(isset($_POST['submit'])){
$email=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$unid=random_bytes(10);
$unid=bin2hex($unid);
$db=new DB();
$sql="INSERT INTO hdms_tickets (ticket_id,status,email,subject,message)
VALUES ('$unid','0','$email','$subject','$message')" or die("<script>alert('Error');</script>");
$inset=$db->conn->query($sql);
if($inset){
$success='Your ticket has been created. Your ticket id is '.$unid ;
$to = $email;
$subject = "helpdesk support Ticket";
// 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";
$txt = "Dear your tickets has been sent to our help desk support team and we will back to you shortly. and here your ticket id $unid please keep your ticket id";
$headers = "From: helpdesk#gmail.com" . "\r\n";
mail($to,$subject,$txt,$headers);
}else{
$error = "Ticket did not send!";
}
echo '<script>showAlert();window.setTimeout(function () {HideAlert();},3000);</script>'; echo "<meta http-equiv='refresh' content='0;url=view_ticket.php'>"; }
the tickets submits to the backend and received by the staff but the problem is that the email is not automatically send to the user once the user submit the ticket i actually upload this to online sever this is for my final project Thank you in advance have a great day!

send fields of form in email with php

I am trying to get all the fields of a html form and sent them by email when the submit button is pressed.
But it doesn't work and I don't know why.
When I test the send button, nothing display in action.php page I don't know why.
I made method="post" and action=action.php in form tag.
HTML FORM
<form action="action.php" method="POST">
<div class="p pb-3"><strong>Feel free to contact me </strong></div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-user-circle"></i></span>
<input class="form-control" type="text" name="name" placeholder="Name" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-file-text"></i></span>
<input class="form-control" type="text" name="subject" placeholder="Subject" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="input-group"><span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input class="form-control" type="email" name="mail" placeholder="E-mail" required="required"/>
</div>
</div>
</div>
<div class="row mb-3">
<div class="col">
<div class="form-group">
<textarea class="form-control" name="message" placeholder="Your Message" required="required"></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col">
<button class="btn btn-primary" type="submit" name="submit" value="Send">Send</button>
</div>
</div>
</form>
```.
PHP CODE
``` code
<?php
echo 'bonjour'
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$subjectF=$_POST['subject'];
$msg=$_POST['message'];
$to='boussidan.raphael#gmail.com';
$subject='Form Submission';
$message="Name :".$name."\n"."Subject :".$subjectF."\n"."Wrote the following :"."\n\n".$msg;
$headers="From: ".$email;
if(mail($to, $subjectF, $message, $headers)) {
echo "<h1>Sent Successfully! Thank you"." ".$name.", I will contact you shortly!</h1>";
echo "Message :"." ".$message. , .$subjectF., .$email.
}
else{
echo "<h1>Something went wrong!</h1>";
}
}
?>
If you are making website not on local server, php mail will be probably turned off, also try https://github.com/PHPMailer/PHPMailer it is if mail does not work, cuz from your question I did not understand what is not working. Another thing if you are doing your php code into another file, not in the file where your html, you don't have to put
if(isset($_POST['submit']))
because if you are doing it in another file it means you are already pressed button to make action in that file

PHP sending email but not getting data from HTML Form [duplicate]

This question already has answers here:
empty $_POST in PHP mail()
(2 answers)
phpmailer how to check if field is empty sintax
(2 answers)
Closed 4 years ago.
I am trying to get some data, like name, email, etc. from an HTML form and sending that data to my gmail. I am getting an email with 'You have recieved an email from .' and 'No Sender' and 'No subject' as the email details.
Here is the PHP:
<?php
if(isset($_POST['submit'])) {
$name = $_POST['first_name'];
$subject = $_POST['subject'];
$mailFrom = $_POST['email'];
$message = $_POST['message'];
$mailTo = "tamiroffen#gmail.com";
$headers = "From: " . $mailFrom;
$txt = "You have recieved an email from " . $name . ".\n\n" . $message;
mail($mailTo, $subject, $txt, $headers);
header("Location: index.html?mailsend");
}
?>
Here is the form section snippet of the HTML:
<form action="contact_form_process.php" method="POST">
<section id="contact" class="py-3">
<div class="container">
<div class="row">
<div class="col-md-9 mx-auto">
<div class="card p-4">
<div class="card-body">
<h3 class="text-center lato-font">Please Fill Out This Form To Contact Us</h3>
<hr>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input id="first_name" name="first_name" type="text" class="form-control" placeholder="First Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="last_name" type="text" class="form-control" placeholder="Last Name">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="email" type="text" class="form-control" placeholder="Email">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<input id="phone_num" type="text" class="form-control" placeholder="Phone Number">
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<textarea class="form-control" name="" id="message" rows="10" placeholder="Message"></textarea>
</div>
</div>
</div>
</div>
<div class="card-footer">
<button type="submit" name="submit" class="btn btn-outline-success btn-block">Send</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>

Form to Email 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!

Bootstrap contact form not function -php

I had coded html and php but cloudsblack84#gmail.com(mail address) still cannot receive mail form my website ( http://cloudsblack.info/ ) and at the end when I clicked the submit button will go into blank page (http://cloudsblack.info/index.php) . Sorry I am just beginner on web design need to learn a lot from you guys .
HTML PART
<!-- Contact Section -->
<section id="contact" class="contacts-section">
<div class="container content-lg">
<div class="title-v1">
<h2>Contact Us</h2>
<p>I'm always happy to hear from you. Please contact or email me for appointment or service enquiry.</p>
</div>
<div class="row contacts-in">
<div class="col-md-6 md-margin-bottom-40">
<ul class="list-unstyled">
<li><i class="fa fa-home"></i> Kuala Lumpur</li>
<li><i class="fa fa-phone"></i> (6)016-7187764</li>
<li><i class="fa fa-envelope"></i> -removed-email-</li>
</ul>
</div>
<div class="col-md-6">
<form method="post" action="index.php">
<label>Name</label>
<div class="row margin-bottom-20">
<div class="col-md-7 col-md-offset-0">
<input type="text" name="name" class="form-control">
</div>
</div>
<label>Email<span class="color-red">*</span></label>
<div class="row margin-bottom-20">
<div class="col-md-7 col-md-offset-0">
<input type="text" name="email" class="form-control">
</div>
</div>
<label>City</label>
<div class="row margin-bottom-20">
<div class="col-md-7 col-md-offset-0">
<input type="text" name="city" class="form-control">
</div>
</div>
<label>Telephone</label>
<div class="row margin-bottom-20">
<div class="col-md-7 col-md-offset-0">
<input type="text" name="telephone" class="form-control">
</div>
</div>
<label>Interested</label>
<div class="row margin-bottom-20">
<div class="col-md-7 col-md-offset-0">
<input type="text" name="interested" class="form-control">
</div>
</div>
<label>Message</label>
<div class="row margin-bottom-20">
<div class="col-md-11 col-md-offset-0">
<textarea rows="8" name="message" class="form-control"></textarea>
</div>
</div>
<p><button type="submit" name="submit" class="btn-u btn-brd btn-brd-hover btn-u-dark">Send Message</button></p>
</form>
</div>
</div>
</div>
PHP PART
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$city = $_POST['city'];
$telephone = $_POST['telephone'];
$interested = $_POST['interested'];
$message = $_POST['message'];
$submit = $_POST['submit'];
if($submit){
$from = 'From: -removed-domain-'."\r\n";
$to = '-removed-email-';
$subject = "Message from -removed-domain-";
$body = "".
"From: ".$name."\n".
"E-mail: ".$email."\n".
"City: ".$city."\n".
"Telephone: ".$telephone."\n".
"Interested: ".$interested."\n".
"Message: ".$message."\n";
if(mail($to, $subject, $body, $from)){
echo '<p>Your message has been sent!</p>';
}
else{
die('<p>Something went wrong, go back and try again!</p>');
}
}
?>
If you see the message Something went wrong, go back and try again! your mail server is incorrectly configured within php.ini or it has timed-out
If you see Your message has been sent!, check your spam folder.
If all else fails, access your mail server logs through WHM or CPanel or contact your hosting provider
$submit = $_POST['submit'];
You havn't given the <button name='submit'> a value, if($submit){ is false/non-existent in your POST data.
Still not a reason for the blank page, need to look at your apache/php error logs or ask your hosting provider.

Categories