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>
<a href="pages-faq.php?id=<?php echo $_SESSION["login_key"];?>" class="btn btn-outline-secondary">Back</a>
</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!