Send data to a pdf file and email

0

Good afternoon I would like to save data from a form of a html page when users register and submit in a pdf file and be sent to a predefined email but I do not know how to do this, I have the form created as follows: / p>

    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Formulário</title>
</head>
<body>
 <h2> Preencha o formulário abaixo para participar no curso de Linux Administração</h2><br/>

<form action="Script_do_Formulario.php" method="post">

<!-- DADOS PESSOAIS-->
<fieldset>
 <legend>Dados Pessoais</legend>
 <table cellspacing="10">
  <tr>
   <td>
    <label for="nome">Nome: </label>
   </td>
   <td align="left">
    <input type="text" name="email">
   </td>
   <td>
    <label for="sobrenome">Apelido: </label>
   </td>
   <td align="left">
    <input type="text" name="sobrenome">
   </td>
  </tr>
  <tr>
   <td>
    <label>Data de Nascimento: </label>
   </td>
   <td align="left">
    <input type="text" name="dia" size="4" maxlength="2" value="dd"> 
   <input type="text" name="mes" size="6" maxlength="2" value="mm"> 
   <input type="text" name="ano" size="8" maxlength="4" value="aaaa">
   </td>
  </tr>
  <tr>
   <td>
    <label for="rg">Localidade: </label>
   </td>
   <td align="left">
    <input type="text" name="rg" size="13" maxlength="13"> 
   </td>
  </tr>
  <tr>
   <td>
    <label>Código Postal:</label>
   </td>
   <td align="left">
    <input type="text" name="cpf" size="9" maxlength="9"> - <input type="text" name="cpf2" size="2" maxlength="2">
   </td>
  </tr>
 </table>
</fieldset>

<br />
<!-- ENDEREÇO -->
<fieldset>
 <legend>Morada</legend>
 <table cellspacing="10">

  <tr>
   <td>
    <label for="rua">Rua:</label>
   </td>
   <td align="left">
    <input type="text" name="rua">
   </td>
   <td>
    <label for="numero">Numero:</label>
   </td>
   <td align="left">
    <input type="text" name="numero" size="4">
   </td>
  </tr>
  <tr>
   <td>
    <label for="bairro">Localidade: </label>
   </td>
   <td align="left">
    <input type="text" name="bairro">
   </td>
  </tr>
  <tr>
   <td>
    <label for="estado">Distrito:</label>
   </td>
   <td align="left">
    <select name="estado"> 
    <option value="av">Aveiro</option> 
    <option value="be">Beja</option> 
    <option value="br">Braga</option> 
    <option value="bg">Bragança</option> 
    <option value="cb">Castelo Branco</option> 
    <option value="cm">Coimbra</option> 
    <option value="ev">Évora</option> 
    <option value="fr">Faro</option> 
    <option value="gd">Guarda</option> 
    <option value="lr">Leiria</option> 
    <option value="lx">Lisboa</option> 
    <option value="Pg">Portalegre</option> 
    <option value="pt">Porto</option> 
    <option value="st">Santarém</option> 
    <option value="sb">Setúbal</option> 
    <option value="vc">Viana do Castelo</option> 
    <option value="vr">Vila Real</option> 
    <option value="vs">Viseu</option> 
    <option value="im">Ilha da Madeira</option> 
    <option value="ia">Ilha dos Açores</option> 
    </select>
   </td>
  </tr>
  <tr>
   <td>
    <label for="cidade">Cidade: </label>
   </td>
   <td align="left">
    <input type="text" name="cidade">
   </td>
  </tr>
  <tr>
   <td>
    <label for="cep">Código Postal: </label>
   </td>
   <td align="left">
    <input type="text" name="cp" size="3" maxlength="4"> - <input type="text" name="cp2" size="2" maxlength="3">
   </td>
  </tr>
 </table>
</fieldset>
<br />

<!-- DADOS DE LOGIN -->
<fieldset>
 <legend>Contacto Email</legend>
 <table cellspacing="10">
  <tr>
   <td>
    <label for="email">E-mail: </label>
   </td>
   <td align="left">
    <input type="text" name="email">
   </td>
  </tr>
  </table>
</fieldset>
<br />
<input type="submit">
<input type="reset" value="Limpar">
</form>
</body>
</html>
    
asked by anonymous 25.03.2018 / 19:18

1 answer

0

Just by using HTML you will not be able to do it in an easy way (there are JavaScript libraries that could handle this) but something simple to implement, but requiring a client installed and configured on the user's computer, is simply to do:

<form action="mailto:«conta de e-mail»" method="get">
   ...
</form>

Then the form data will be sent to the e-mail address indicated in the form.

But I also saw that your form, in the beginning, would send the data to a program in PHP, the "Script_of_Formulario.php", in this case your doubt would also be in this language?

So a very simple program to receive and send form data to a specific email address would look something like this:

<?php
    /* lê os campos via POST */
    $nome = $_POST['nome'];
    ...

    /* alguma validação */
    ...

    /* monta a mensagem */
    $mensagem = "Ficha de Inscrição\n".
        "- - - - - - - - - - - - - - - - - - - -\n".
        "Nome : ".$nome."\n".
        "- - - - - - - - - - - - - - - - - - - -\n";

    mail('[email protected]','Ficha de Inscrição', $mensagem);
?>

Of course, this program retrieves only the "name" of the form (it is possible to understand the logic to do the same with the other fields) and assembles the body of a message to be sent by PHP's own mail function. p>     

25.03.2018 / 21:35