ticket email not sending - php

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!

Related

Why isn't my PHP form working? I do receive the email but there is no content in it

PHP form on my website isn't responding well. It would be appreciated if someone could help me.
This is the HTML Code of the form
<form action="contactform.php" method="post" name="form" class="p-5 bg-white">
<div class="row form-group">
<div class="col-md-6 mb-3 mb-md-0">
<label class="text-black" for="fname">First Name</label>
<input type="text" id="fname" class="form-control">
</div>
<div class="col-md-6">
<label class="text-black" for="lname">Last Name</label>
<input type="text" id="lname" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="email">Email</label>
<input type="email" id="email" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="subject">Subject</label>
<input type="subject" id="subject" class="form-control">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label class="text-black" for="mssg">Message</label>
<textarea name="mssg" id="mssg" cols="30" rows="7" class="form-control" placeholder="Write your notes or questions here..."></textarea>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="submit" value="Send Message" class="btn btn-primary py-2 px-4 text-white">
</div>
</div>
</form>
This is the PHP Code
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$to = "alyyashar#gmail.com";
$subject = "New email from your site!";
$fname = $_POST['fname'];
$email = $_POST['email'];
$message = $_POST['message'];
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$title = '<h3>Hello! You have received a new mail from your website!</h3>';
$body = "$title
<br/>
<b>From:</b> $fname
<br/>
<b>E-Mail:</b> $email
<br/>
<b>Message:</b>\n$message
<br/>
<br/>";
if (mail($to, $subject, $body, $headers)){
echo "<h1>Sent Successfully! Thank you"." ".$fname.", We will contact you shortly!</h1>";
} else {
echo "Something went wrong!";
}
}
?>
<br>
Back to Homepage
This is the email I receive
Screenshot of the email
When I enter information into the form and click send message, I do receive the email but there is no content in it.
The form elements have no name attributes, which is what the browser uses to send their name/value pairs to the server. So while it's posting the form, none of the values are being included.
For example, this:
<input type="text" id="fname" class="form-control">
Should be this:
<input type="text" id="fname" class="form-control" name="fname">
The same fix would need to be repeated for the remaining form elements.

PHP Send Email From HTML Form

I want to get an email from an html form. I was following a tutorial that used PHP, which I have never used before, and it doesn't seem to work. After I hit submit, the php page opens, but an email is not sent to me. Can someone please help me.
HTML(A couple inputs like name and email, etc. and a submit button at the bottom):
<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" 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">
<input type="submit" class="btn btn-outline-success btn-block" value="Send">
<button type="submit" class="btn btn-outline-success btn-block">Send</button>
</div>
</div>
</div>
</div>
</div>
</section>
</form>
Here is my PHP:
<?php
// Subject and Email Variables
$emailSubject = 'Test Email';
$webMaster = 'tamiroffen#gmail.com';
// Gathering Data Variables
$first_nameField = $_POST['first_name'];
$last_nameField = $_POST['last_name'];
$emailField = $_POST['email'];
$phone_numField = $_POST['phone_num'];
$messageField = $_POST['message'];
$body = <<<EOD
<br><hr><br>
Email: $emailField <br>
Name: $first_nameField <br>
Phone Number: $phone_numField <br>
Message: $message <br>
EOD;
$headers = "From: $emailField\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
?>
Thank you!
mail() needs to be enabled as #esqew points out in his comment - this would look something like this (this is on my BigRock environment YMMV) -
ini_set("include_path", '<path to php>' . ini_get("include_path") );
require_once "Mail.php";
Also, if you are using GMail, you also need to set up GMail to allow sending mail through SMTP - https://support.google.com/mail/answer/7126229?visit_id=636741342414654323-2069917091&hl=en&rd=1
$webMaster = 'tamiroffen#gmail.com';
I assume this is the address where the emails are sent to. From what I've heard, PHP mail() function doesn't work for gmail(if it's on the receiver end).
You can just use another email provider like hotmail or any and forward emails from it to your gmail
Watch this video if you need more info on it, How to create a PHP Contact Form Tutorial

Unable to send an email after clicking on submit button in php

Trying to send an email not displaying any error message or anything just refreshing the page that it.
I am trying an email through contact form but its not working.Here is the code for that. tried by doing echo but it is not working .not displaying any error as well.
contact and contactus:
<?php ob_start();
if(isset($_POST['submit'])) {
$to = "abc#gmail.com";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$txt = $_POST['comment'];
$headers = "From: " .$email . "\r\n" .
"CC: xyz#gmail.com";
mail($to,$subject,$txt,$headers);
header("Location: contact.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>HMS System</title>
</head>
<body>
<div class="container">
<div class="page-header">
<h2>Contact Us Form</h2>
</div>
<form class="form-horizontal" action="contactus.php" method="post" role="form">
<div class="form-group">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="name" placeholder="Insert your Name" id="name">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email Address</label>
<div class="col-sm-8">
<input type="email" class="form-control" name="email" placeholder="Email Address" id="email">
</div>
</div>
<div class="form-group">
<label for="subject" class="col-sm-2 control-label">Subject</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="subject" placeholder="Subject" id="subject">
</div>
</div>
<div class="form-group">
<label for="comments" class="col-sm-2 control-label">Comment</label>
<div class="col-sm-8">
<textarea class="form-control" rows="10" name="comment" style="resize:none;"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-8">
<input type="submit" value="Send Message" name="submit_contact" class="btn btn-block btn-danger" id="subject">
</div>
</div>
</form>
</section>
</article>
</div>
<div style="width:50px;height:50px;"></div>
</body>
use this
if(isset($_POST['submit_contact']))
If you are doing it from your local server, you will have to setup your mail properly in ini then only you will be able to send mail from your local machine.
A better approach would be to wrap the mail function in a statement. Mail is returning a bool value. And beginn as simple as possible.
error_reporting (E_ALL);
$to = "mail#whatever.com"
// ... your settings ...
if ( mail ( $to , $subject , $message ) ) {
// do when ok
}
else {
// do when error
}
To verify that you receive all values from $_POST do
echo '<pre>';
print_r ($_POST);
echo '</pre>';

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

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']))

Mail not sending when submitting form

For some reason this form is not working and not sending out emails through submitting the form. It says the form has successfully submitted but it never sends anything. What is causing the problem? Please help.
<?php
$id = protect($_GET['id']);
$sql = mysql_query("SELECT * FROM items WHERE id='$id'");
if(mysql_num_rows($sql)==0) { header("Location: $web[url]"); }
$row = mysql_fetch_array($sql);
?>
<section class="dashboard content">
<div class="container">
<div class="row">
<div class="span12">
<h3>Contact with Owner</h3>
<?php
if(isset($_POST['do_send'])) {
$item_name = protect($_POST['item_name']);
$name = protect($_POST['name']);
$email = protect($_POST['email']);
$subject = protect($_POST['subject']);
$message = protect($_POST['message']);
if(empty($name) or empty($email) or empty($subject) or empty($message)) { echo error("All fields are required."); }
elseif(!isValidEmail($email)) { echo error("Please enter a valid email address."); }
else {
$get = mysql_fetch_array(mysql_query("SELECT * FROM admins ORDER BY id LIMIT 1"));
$admin_email = $get['email'];
$to = $admin_email;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$subjectt = $web[sitename].' - Message from '.$name;
$messaget = '<html><body><table border="0" cellspacing="2" cellpadding="2"><tr><td><span style="font-size:30px;font-weight:bold;">'.$web[sitename].'</span><br></td></tr><tr><td>You have new message from user for item. Here is message details:</td></tr><tr><td>From: '.$name.' ('.$email.')</td></tr><tr><td>Item: '.$row[name].'</td></tr><tr><td>Subject: '.$subject.'</td></tr><tr><td>Message:<br/>'.nl2br($message).'</td></tr></table></body></html>';
mail($to, $subjectt, $messaget, $headers);
echo success("Your message was sent successfully.");
}
}
?>
<form action="" method="POST">
<div class="bg-color white rounded-top">
<div class="box-padding">
<div class="control-group">
<label class="control-label" for="inputUsername">Item</label>
<div class="controls">
<input type="text" id="inputUsername" name="item_name" class="input-block-level" disabled value="<?php echo $row['name']; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Your name</label>
<div class="controls">
<input type="text" id="inputUsername" name="name" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Your email address</label>
<div class="controls">
<input type="text" id="inputUsername" name="email" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Subject</label>
<div class="controls">
<input type="text" id="inputUsername" name="subject" class="input-block-level">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputUsername">Message</label>
<div class="controls">
<textarea name="message" class="input-block-level" rows="4"></textarea>
</div>
</div>
</div>
</div>
<div class="bg-color dark-blue rounded-bottom">
<div class="box-padding narrow-horizontal">
<div class="control-group">
<div class="controls">
<button type="submit" name="do_send" class="btn btn-primary">Send</button>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The contact form is here: http://rocketraiser.com/contact/13546224#sthash.HnYyaGGz.0o0gQ4nS.dpbs
The contact form brings in the individual item name.
Please can you show me how to fix this. Thank you very much.
-Harry
Could be that the form has no action, by the looks of that code, the action should be the same URL the form is in

Categories