K
K
kickass772022-03-04 07:03:41
AJAX
kickass77, 2022-03-04 07:03:41

Why does 405 Not allowed appear on different hostings?

Hello. On one hosting - everything is super, on the other, when sending an ajax request, such an error appears and the GET AJAX request is not executed and the further function.

ajax request:

<script>
    	$("#feedback-form").click(function () {
        var name = "Новый клиент";
        var phone = $("#phone").val();

        $.ajax({
            url: "include/mail.php",
            cache: false,
            data: ({type:"mail", name:name, 
                phone:phone
            }),
            success: function(html){
            	$("#feedback-form").hide();
                 $("#mail_ajax").html(html);
            }
        });
        return false;
    });
</script>


Handler

if($_GET['type'] == 'mail') {
        $name = trim($_GET['name']);
        $phone = trim($_GET['phone']);

        $fromMail = '[email protected]';
        $fromName = '[email protected] НОВАЯ ЗАЯВКА';


        $emailTo = '[email protected]';
        $subject = 'Заявка с сайта';
        $subject = '=?utf-8?b?'. base64_encode($subject) .'?=';
        $headers = "Content-type: text/plain; charset=\"utf-8\"\r\n";
        $headers .= "From: ". $fromName ." <". $fromMail ."> \r\n";

        $body = "Получено письмо с сайта \n Имя: $name\nТелефон: $phone";

        if (strlen($phone) > 0) {
            if($mail = mail($emailTo, $subject, $body, $headers, '-f'. $fromMail )) {
                echo "Сообщение отправлено";
            }else{
                echo "Не отправлено";
            };
        }
    }


The path is right everywhere, nothing has changed. Identical files and everything works on one hosting, on the other - no.
The htaccess file is missing.
The only difference is a non-working site in the rf domain zone.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2022-03-04
@Rsa97

Perhaps the reason is that the mail function is blocked on some hostings.
Given that an email sent through this feature is almost guaranteed to end up in spam, it still shouldn't be used in production. Replace with PHPMailer sending via SMTP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question