0

Eu tenho o seguinte código, em que quando acabo de preencher o formulário quero receber um e-mail com a confirmação dos dados e posteriormente abrir uma página em que irei redirecionar:

Contudo, após o código que apresento estou com algumas dificuldades em acabar;

Conseguem ajudar?

<h2><td><font color ="#336699"> Formulario</td></font></h2>
<form action="http://www.teste.com/" id="ContactUsCaptchaWebForm"    method="post" onsubmit="return ValidateForm(this);" target="_top">
     <input name="skip_WhereToSend" type="hidden" value="[email protected]"/>
     <input name="skip_SnapHostID" type="hidden" value="D2YEXZTGA4Q2" />
     <input name="skip_WhereToReturn" type="hidden" value="http://www.torangis.com/" />
     <input name="skip_Subject" type="hidden" value="Contact Us Form" />
     <input name="skip_ShowUsersIp" type="hidden" value="1" />
     <input name="skip_SendCopyToUser" type="hidden" value="1" />
     <script type="text/javascript">
         function ValidateForm(frm) {
             if (frm.Name.value == "") {alert('Nome é requerido');frm.Name.focus();return false;}
             if (frm.Email.value == "") {alert('É necessário preencher os campos obrigatórios');frm.Email.focus();return false;}
             if (frm.Email.value.indexOf("@") < 1 || frm.Email.value.indexOf(".") < 1) {alert('É necessário um endereço de e-mail válido');frm.Email.focus();return false;}
             if (frm.Telemovel.value == "") {alert('É necessário preencher os campos obrigatórios');frm.Telemovel.focus();return false;}
             if (frm.skip_CaptchaCode.value == "") {alert('É necessário preencher os campos obrigatórios');frm.skip_CaptchaCode.focus();return false;}
             return true; }
        function ReloadCaptchaImage(captchaImageId) {
             var obj = document.getElementById(captchaImageId);
             var src = '' + obj.src;
             obj.src = '';
             var date = new Date();
             var pos = src.indexOf('&rad=');
             if (pos >= 0) { src = src.substr(0, pos); }
             obj.src = src + '&rad=' + date.getTime();
             return false; }
    </script>
    <table border="0" cellpadding="5" cellspacing="0" width="600">
        <tr>
            <td><font face="Arial"><font color ="#000000"> Nome *</td></font>
            <td><input name="Name" type="text" maxlength="60" style="width:350px;" /></td>
       </tr><tr>
            <td><font face="Arial"><font color ="#000000"> E-mail *</td></font>
            <td><input name="Email" type="text" maxlength="60" style="width:350px;" /></td>
      </tr><tr>
           <td><font face="Arial"><font color ="#000000"> Empresa / Loja (Se aplicável) </td></font>
           <td><input name="Empresa" type="text" maxlength="43" style="width:350px;" /></td>
      </tr><tr>
           <td><font face="Arial"><font color ="#000000"> Concelho </td></font>
           <td><input name="Concelho" type="text" maxlength="60" style="width:350px;" /></td>
     </tr><tr>
           <td><font face="Arial"><font color ="#000000"> Telemóvel *</td></font>
           <td><input name="Telemovel" type="text" maxlength="43" style="width:350px;" /></td>
     </tr><tr>
           <td><font face="Arial"><font color ="#000000"> Mensagem opcional </td></font>
           <td><textarea name="Comentario" rows="4" cols="50" style="width:350px;"></textarea></td>
    </tr><tr>
          <td colspan="2" align="center"> <br />
          <table border="0" cellpadding="0" cellspacing="0">
    <tr>
          <td colspan="2" style="padding-bottom:18px;">
              <tr valign="top"><td> <b><font face="Arial"><font size="2"><center>Inserir letras *</center></b>
              <input name="skip_CaptchaCode" type="text" style="width:80px;" maxlength="6" />
              </td><td>
                  <a href="http://www.teste.com/"><img id="CaptchaImage" alt="Contact Us form" title="HTML code for Contact Us form" style="margin-left:20px;"  src="http://www.SnapHost.com/captcha/CaptchaImage.aspx?id=D2YEXZTGA4Q2&ImgType=2" /></a><br />
                  <a href="#" onclick="return ReloadCaptchaImage('CaptchaImage');"><span style="font-size:12px;"><font face="Arial">Renovar imagem</span></a> </td></tr>
        </table> <br /><font face="Arial">
        * Campos obrigatórios &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
        <form enctype="text/plain" method="get" action="mailto:[email protected]">
             <input type="submit" value="Enviar">
        </form>
    </td></tr>
    </table><br />
</form>


<html>
    <head>
        <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; 
        $empresa = $_REQUEST['empresa'] ; $telefone = $_REQUEST['telefone'] ;
        $concelho = $_REQUEST['concelho'] ; $message = $_REQUEST['message'] ;
        mail( "[email protected]", 
        "Quero fazer activações através do teste da teste",
        "#REVENDEDOR         ################################################################ 
        EMPRESA/LOJA:$empresa NOME:$name EMAIL: $email TELEFONE: $telefone 
        CONCELHO:$concelho MENSAGEM: $message ", "from: [email protected]"); 
        header( "Location: http://teste.teste.com/resposta2.php" ); ?>
    </head>
    <body>
        <br>
    </body>
</html>

Muito Obrigado

7
  • Qual seria o código PHP que enviaria o e-mail?
    – Woss
    14/09/2017 às 10:07
  • Seria o seguinte: <?php $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $empresa = $_REQUEST['empresa'] ; $telefone = $_REQUEST['telefone'] ; $concelho = $_REQUEST['concelho'] ; $message = $_REQUEST['message'] ; mail( "[email protected]") EMPRESA/LOJA:$empresa NOME:$name EMAIL: $email TELEFONE: $telefone CONCELHO: $concelho MENSAGEM: $message ", "from: [email protected]"); header( "Location: teste.com/resposta.php" ); ?>
    – Ricardo
    14/09/2017 às 10:52
  • Coloque junto a pergunta esse código
    – Woss
    14/09/2017 às 10:53
  • Não entendi, como assim junto a pergunta?
    – Ricardo
    14/09/2017 às 10:56
  • Da mesma maneira que colocou o HTML, basta editar a pergunta.
    – Woss
    14/09/2017 às 10:57

1 Resposta 1

0

Para facilitar, cria um arquivo separado para o envio, do jeito que está ele tentaria enviar sempre que o html for executado.

enviar_email.php

<?php 
    $name = $_REQUEST['name'] ; 
    $email = $_REQUEST['email'] ; 
    $empresa = $_REQUEST['empresa'] ; 
    $telefone = $_REQUEST['telefone'] ;
    $concelho = $_REQUEST['concelho'] ; 
    $message = $_REQUEST['message'] ;

    @mail( "[email protected]", 
    "Quero fazer activações através do teste da teste",
    "#REVENDEDOR         ################################################################ 
    EMPRESA/LOJA:$empresa NOME:$name EMAIL: $email TELEFONE: $telefone     CONCELHO: 
    $concelho MENSAGEM: $message ", "from: [email protected]"); 

    header("Location: http://teste.teste.com/resposta2.php"); 
?>

no seu arquivo .html

substitua seu action do formulário por: <form action="http://www.teste.com/enviar_email.php" [...]>

Lembrando que, para testar localmente você precisa de um servidor smtp configurado; quando você utiliza From: ..., e o e-mail não for válido ou não fizer parte do seu domínio bem certo que receberá como span, ou nem chegará a receber dependendo do servidor que recebe o e-mail.

3
  • Muito obrigado pela ajuda! Continuação de grande dia.
    – Ricardo
    14/09/2017 às 13:44
  • Sabe qual a função para dar o resultado de erro quando a imagem do Captcha for diferente do que tenho na caixa de texto? Neste momento qualquer valor é aceite, e não sei qual a função a ser utilizada.
    – Ricardo
    14/09/2017 às 13:55
  • Suas perguntas tem sido muito vaga, vc usa alguma framework; vc quem fez o captcha; que tipo de erro você fala? 15/09/2017 às 11:53

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .