Contact form for PHP

Asked

Viewed 404 times

1

Hello, I created a form in html, but not this functional , why I have little knowledge in PHP, how can I develop the script to send the email to my Hotmail?

This is my form

      <main>
              <section class="contato">    
                    <div class="container">
                        <form>
                            <div class="cols">
                                <div class="col">
                                    <div class="form-group">
                                        <input type="text" placeholder="Nome" required>
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="form-group">
                                        <input type="email" placeholder="Email" required>
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="form-group">
                                        <input type="number" placeholder="Telefone">
                                    </div>
                                </div>
                                <div class="col">
                                    <div class="form-group">
                                        <select>
                                            <option>Selecione uma opção</option>
                                            <option>Orçamento</option>
                                            <option>Duvidas Referente ao Serviço</option>
                                            <option>Outro</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="text-area">
                                <textarea placeholder="Escreva sua mensagem"></textarea>
                            </div>
                         
                            <div class"form-group">
                                <button class="botao medio"><i class="fa fa-envelope" aria-hidden="true"></i> Enviar</button>
                            <div>
                 
                            
                            
                        </form>
                    </div>
              </section>
         </main>

  • You can use the library Phpmailer or the native function mail() PHP. But try [Edit] your question and give more details, for example what is not functional, some error, some warning, your code. A more concrete question.

  • @Uzumakiartanis Sorry, I actually only have the html form, I haven’t written the code in php yet, so I need help on how to do the script

  • Please put the code here, specify your question. What do you have ready? Show us! :)

  • I just finished editing the question

  • Search a little on the subject, even on the links I posted before or on google even, then develop something and come back with a more concrete doubt (a mistake maybe).

  • You have several questions right here at https://answall.com/search?q=qnviar+email+%5Bphp%5D I recommend this one here https://answall.com/questions/23602/como-mail-com-php and this one also https://wiki.locaweb.com.br/pt-br/Envio_autenticado_na_revenda

  • Possible duplicate of Sending email via Phpmailer to Gmail

Show 2 more comments

1 answer

1


First you must configure the form so that it can send the data somewhere:

<form action="algumapagina.php" method="post"> //Action é a pagina para qual o formulario vai enviar e methos como ele vai enviar os dados

Now set the name of the properties to get their respective values:

<input name="nome" type="text" placeholder="Nome" required>

<input name="email" type="email" placeholder="Email" required>

<input name="numero" type="number" placeholder="Telefone">

<select name="tipo"></select>

<textarea name="mensagem" placeholder="Escreva sua mensagem"></textarea>

After doing this, you have to pick up these values on the page from which you submitted the user:

if(isset($_POST)){ //Checa se os dados foram enviados
    $nome = $_POST['nome'];
    $email = $_POST['email'];
    $numero = $_POST['numero'];
    $tipo = $_POST['tipo'];
    $mensagem = $_POST['mensagem'];
}

Set the body of the email:

$conteudo = "$nome\n$email\n$numero\n$tipo\n$mensagem";

And send the email normally:

mail($destinatario, $assunto, nl2br($conteudo), "From: [email protected]");
//Onde a variavel $assunto contem o assunto do email, $destinatario, pra quem o email será enviado e From, a partir de que email ele virá

Don’t forget to set up php.ini!

Behold that, if you have more questions. Or official documentation.

  • this last line mail($destinatario, $assunto, nl2br($conteudo), "From: [email protected]"); I put for example: $My-name ? E for which server and how do I configure php.ini ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.