'PHP email script is not working in gitlab
I developed one HTML site and for that, I but one PHP email script, and I submitted the form using ajax I uploaded the file into normal Cpanel and I test it's working fine without any issues.
But after the I uploaded the same files I created a new project in GitLab and I uploaded into that and I connected the project to Cloudflare and Cloudflare connected with my domain and my site is loading without issue but after I filled the form and press the submit form in the console it's showing the 405 error. I attached my codes and error screenshot. Please help me fix this issue.
My Script
<script>
$(function () {
$('form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'sendmail.php',
data: $('form').serialize(),
success: function () {
$('#exampleModalCenter').modal('hide');
$('#exampleModalCenter01').modal('show');
setTimeout(function(){
$('#exampleModalCenter01').modal('hide');
},3000);
}
});
});
});
</script>
My PHP code
<?php
$name = $_POST["inputName"];
$company = $_POST["inputCompany"];
$industry = $_POST["inputIndustry"];
$country = $_POST["inputCountry"];
$phone = $_POST["inputPhone"];
$email = $_POST["inputEmail"];
$to = $email;
$subject = 'New Form Submission';
$from = '[email protected]';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Create email headers
$headers .= 'From: '.$from."\r\n".
$headers .= 'Cc: '.$from."\r\n".
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#000;">1Kind New Form Submission</h1>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Name</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$name.'</p>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Company</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$company.'</p>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Industry</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$industry.'</p>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Country</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$country.'</p>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Phone</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$phone.'</p>';
$message .= '<p style="color:#000;font-size:13px;font-weight:bold">Email</p>';
$message .= '<p style="color:#000;font-size:13px;">'.$email.'</p>';
$message .= '<p style="color:#000;font-size:13px;">Thank you</p>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|