A
A
Arthur2021-09-22 22:02:46
PHP
Arthur, 2021-09-22 22:02:46

Problem with php form?

I've been writing the site myself for more than 2 years (front-end) I
started studying php recently, at the moment I'm making a feedback form.
But the problem is that when the user enters data in the input, the else method is triggered, and therefore the data that he entered does not come to the mail

Here is the PHP code

<?php
    $tel = $_POST['tel'];
    $email = $_POST['email'];

    $tel = htmlspecialchars[$tel];
    $email = htmlspecialchars[$email];

    $tel = urldecode[$tel];
    $email = urldecode[$email];

    $tel = trim[$tel];
    $email = trim[$email];

    if(mail("[email protected]",
        "Новое писмо с сайта",
        "Телефон: ".$tel. "\n".
         "Почта: ".$email. "\n",
         "From: [email protected]")
    ) {
         echo ('Ждите звонка');
    }

    else {
        echo('Не');
    }
?>


Look at my code, if you find an error please let me know. Thanks in advance )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
ThunderCat, 2021-09-22
@ThunderCat

First, enable error reporting.
Secondly, check the data that came from the client.
Thirdly, there is a magical var_dump() function that allows you to see what is happening in general and what goes where, use it as often as possible in such situations.
Fourthly, you have already been advised to use ready-made libraries for sending mail, which do not depend on the server settings and can also use arbitrary mail services using the smtp protocol.
For debugging and testing, you can use mail () with the correct data inserted in advance, not through the form, and check if this function works at all, and then draw conclusions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question