1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Rep Power

    Send email and download the file at the same time

    The idea is I know the data of those who downloaded it so I can have a control.


    I have a download link that is caught on the list, which calls a form that the User must complete to trigger the download. The idea is to trigger the download when the guy pressing the submit.

    I'll show you how I did

    this is the page of the form

      <?php           require_once("settings.php");          $id = $_GET['id'];          $list_files = ""; //string onde todos os registros são anexados        $mysql = mysql_connect($db_host, $db_user, $db_password);        mysql_select_db($db_name, $mysql);        $result = mysql_query("SELECT * ,DATE_FORMAT(Data, '%d/%m/%Y') Data FROM $table_name WHERE id = $id"); // selecionando o tabela e formatando a data de forma legivel e     tendo uma condição para o id        while ($row = mysql_fetch_array($result)) {          $id = $row['id']; //Ele salva o ID, que permite reconhecer uma linha          $url_img = $row['File'];          $nomedoarquivo = $row['nomedoarquivo '];        }     ?>      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">     <html xmlns="http://www.w3.org/1999/xhtml">     <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />     <title></title>     <meta name="description" content="#" />     <meta name="keywords" content="#" />     <style type="text/css">     @import url(css/style.css);     </style>     <script language="javascript" type="text/javascript" src="js/mascara.js"></script>     <script language="javascript" type="text/javascript" src="js/ValidaData.js"></script>     <script>     function AbreForm(){     document.getElementById('FORM').style.display="block";        }      function FecharForm(){     document.getElementById('FORM').style.display="none";        }     </script>     </head>     <body>     <div id="container">        <div id="header"><a href="#"><img src="imagens/logo.png" class="logo" /></a></div>        <div id="content">           <div class="campo-upload">              <div class="nav"><a href="index.php"> Voltar</a></div>              <br />              <form method="post" action="formmail.php" enctype="multipart/form-data">                 <input type="hidden" value="<?php echo $id; ?>" name="id" />                 <!-- busca o id do arquivo -->                 <input type="hidden" value="<?php echo $url_img; ?>" name="url_img" />                 <!-- busca o id do arquivo -->                 <fieldset>                    <legend>PREENCHA O FORMULÀRIO PARA EFETUAR O DOWNLOAD</legend>                    <label for="Empresa">Empresa:</label>                    <input type="text" id="Empresa" name="Empresa" size="30" />                    <br />                    <label for="Cnpj">Cnpj:</label>                    <input type="text" id="Cnpj" name="Cnpj" size="30" />                    <br />                    <label for="Nome">Nome:</label>                    <input type="text" id="Nome" name="Nome" size="30" />                    <br />                    <label for="Cpf">Cpf:</label>                    <input type="text" id="Cpf" name="Cpf" size="30" />                    <br />                    <label for="Endereco">Endereço:</label>                    <input type="text" id="Endereco" name="Endereco" size="30" />                    <br />                    <label for="Email">Email:</label>                    <input type="text" id="Email" name="Email" size="30" />                    <br />                    <label for="Telefone">Telefone:</label>                    <input type="text" id="Telefone" name="Telefone" onkeypress="mascara(this, '##-#########')"  maxlength="12"size="30" />                    <br />                    <label for="Download">Arquivo:</label>                    <input type="text" id="Download" name="Download" size="30" value="<?php echo $nomedoarquivo ?>" />                    <br />                    <label for="Observacoes">Observações:</label>                    <textarea  id="Download"  name="Observacoes" rows="5" cols="28"></textarea>                    <br />                    <br />                    <label for="submit"> </label>                    <input type="submit" name="Enviar" value="Enviar e Fazer download"  tabindex="2"/>                    <input type="reset" name="Limpar" value="Limpar"/>                 </fieldset>              </form>              <br />           </div>           <div class="Reader">              <ul>                 <li> <img src="imagens/reader.png" width="54" height="51" class="avatar" />                    <h3>Reader</h3>                    <p>é sempre uma ótima sugestão para quem procura um leitor para PDF de confiança.<a href="http://ardownload.adobe.com/pub/adobe/reader/win/9.x/9.3/ptb/AdbeRdr930_pt_BR.exe">Download</a> </p>                 </li>              </ul>           </div>        </div>        <br />     </div>     <!-- fim container-->      <div id="footer">        <p></p>     </div>     <!-- fim footer-->     </body>     </html>      <?php mysql_close($mysql);?>

    this is the page of formmail.php

    when I call the formmail.php he pulls the file you saved in the format that will not open, not redirects to the list of new

    I need help here in formmail

    <?php            $url_img = $_POST['url_img'];               header("Pragma: public");               header("Expires: 0");               header("Cache-Control: must-revalidate, post-check=0, pre-check=0");     header("Cache-Control: public");     header("Content-Description: File Transfer");     header("Content-Disposition: attachment; filename=$url_img");     header("Content-Type: application/pdf");     header("Content-Transfer-Encoding: binary");     echo ($url_img);       $mensagem = "Empresa: ".$_POST['Empresa']." \n";     $mensagem .= "Cnpj: ".$_POST['Cnpj']." \n";     $mensagem .= "Nome: ".$_POST['nome']." \n";     $mensagem .= "Cpf: ".$_POST['Cpf']." \n";     $mensagem .= "Endereço: ".$_POST['Endereco']." \n";     $mensagem .= "Email: ".$_POST['email']." \n";     $mensagem .= "Telefone: ".$_POST['Telefone']." \n";     $mensagem .= "Download: ".$_POST['Download']." \n";     $mensagem .= "Observações: ".$_POST['Observacoes']." \n";      $mensagem .= "<br>\n Por favor, não responda a esta mensagem pois foi gerada automaticamente e tem caracter informativo apenas.<br>\n";      $headers = "MIME-Version: 1.1\n";     $headers .= "Content-type: text/plain; charset=iso-8859-1\n";     $headers .= "Content-type: text/html; charset=iso-8859-1\n";     $headers .= "Content-type: text/html; charset=utf-8\n";      $headers .= "X-Priority: 1\n";      $emailsender = "getrojob@gmail.com";     //email de quem vai receber     $emaildestinatario = "getrojob@gmail.com";     $assunto = "Formulario de inscrição - Licitação";     if(!mail($emaildestinatario, $assunto, $mensagem, $headers ,"-r".$emailsender))      {     // Se for Postfix - hospedagem linux     $headers .= "Return-Path: " . $emailsender . $quebra_linha;     }       echo '     <script type="text/JavaScript">     alert("Seu e-mail foi enviado com sucesso. Obrigado");     location.href="index.php"     </script>     ';      ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Rep Power
    Please edit you post so it is not all on one line and use [ PHP ] tags not [ CODE ] tags (see the sticky at the top of this forum). Highlight your code then click the PHP icon. Also make sure your headers are absolutely the very first thing you output. Even a space will cause the headers to not work. There can be nothing preceding the first '<?php' on the page that outputs the headers.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo