title: My php script for mailing a form is not working
body: <p>I am trying to set up a form that will send attachments along with the email content, but I have no idea what I am doing.</p>
  
  <p>I am completely new to PHP, and just learned to do the basic mail form work by, basically, trial and error, along with tutorials on the internet. But, when it came to attachments. Now I am completely at loss. And, although the PHP script supposedly runs, and the file is uploaded, all the operation stops all of a sudden. Neither do I get the messages that should show when the scripts finishes running nor do I get an email with the test message and its attachment. </p>
  
  <p>Can anyone help me, or at least walk me through so I can understand what's my error? My HTML and PHP are as follows:</p>
  
  <p>HTML (Form and title)</p>
  
  <pre><code>&lt;h3 style="padding-left:290px"&gt;Consulta de orçamento&lt;/h3&gt;
  &lt;form id="form" method="post" action="formulario_orcamento.php" style="padding-left:100px" enctype="multipart/form-data"&gt;
      &lt;fieldset&gt;
          &lt;label&gt;&lt;input name="Nome" type="text" value="Nome" id="Nome" onBlur="if(this.value=='') this.value='Nome'" onFocus="if(this.value =='Nome' ) this.value=''"&gt;&lt;/label&gt;
          &lt;label&gt;&lt;input name="E-mail" type="text" value="E-mail" id="E-mail" onBlur="if(this.value=='') this.value='E-mail'" onFocus="if(this.value =='E-mail' ) this.value=''"&gt;
          &lt;/label&gt;
          &lt;label&gt;&lt;input name="Telefone" type="text" value="Telefone" id="Telefone" onBlur="if(this.value=='') this.value='Telefone'" onFocus="if(this.value =='Telefone' ) this.value=''"&gt;&lt;/label&gt;
          &lt;label&gt;
              &lt;select name="Duvidas" id="Duvidas" style="height:20px; width: 623px"&gt;
                  &lt;option value="Elaboração de questionários"&gt;Elaboração de questionários&lt;/option&gt;
                  &lt;option value="Amostragem"&gt;Amostragem&lt;/option&gt;
                  &lt;option value="Análise exploratória"&gt;Análise exploratória&lt;/option&gt;
                  &lt;option value="Pesquisas online"&gt;Pesquisas online&lt;/option&gt;
                  &lt;option value="Tabulação"&gt;Tabulação&lt;/option&gt;
                  &lt;option value="Análises específicas"&gt;Análises específicas&lt;/option&gt;
                  &lt;option value="Outras Dúvidas"&gt;Outras Dúvidas&lt;/option&gt;
              &lt;/select&gt;
          &lt;/label&gt;
          &lt;label&gt;&lt;input name="Outras" type="text" value="Outras Dúvidas - Especificar" id="Outras Duvidas" onBlur="if(this.value=='') this.value='Outras Dúvidas - Especificar'" onFocus="if(this.value =='Outras Dúvidas - Especificar' ) this.value=''"&gt;&lt;/label&gt;
          &lt;label&gt;&lt;input name="Arquivos" type="file" style="height:25px"&gt;&lt;/label&gt;
          &lt;label&gt;&lt;textarea name="Mensagem" id="Mensagem" onBlur="if(this.value==''){this.value='Mensagem'}" onFocus="if(this.value=='Mensagem'){this.value=''}"&gt;Mensagem&lt;/textarea&gt;&lt;/label&gt;
          &lt;input type="submit" name="Enviar" id="Enviar" value="Enviar" class="button" style="background:#64d0ff; font-size:14px; color:#fff; display:inline-block; padding:6px 20px 5px 20px; box-shadow:0 1px 1px #fff; width:70px; height:35px" onmouseover="this.style.backgroundColor='#1f497d', this.style.color='#fecf06'" onmouseout="this.style.backgroundColor='#64d0ff', this.style.color='#ffffff'"&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>PHP</p>
  
  <pre><code>&lt;?php
  $name      = $_POST['Nome'];
  $email     = $_POST['E-mail'];
  $telephone = $_POST['Telefone'];
  $message   = $_POST['Mensagem'];
  
  if ($_POST['Duvidas'] = "Outras Dúvidas") {
      $question == $_POST['Outras'];
  } else {
      $question == $_POST['Duvidas'];
  }
  
  $mime_boundary = "==Multipart_Boundary_x" . md5(mt_rand()) . "x";
  $tmp_name      = $_FILES['filename']['tmp_name'];
  $ftype         = $_FILES['filename']['type'];
  $fname         = $_FILES['filename']['name'];
  $fsize         = $_FILES['filename']['size'];
  if (file_exists($tmp_name)) {
      if (is_uploaded_file($tmp_name)) {
          $file = fopen($tmp_name, 'rb');
          $data = fread($file, filesize($tmp_name));
          fclose($file);
          $data = chunk_split(base64_encode($data));
      }
  
      $to      = "quick.analytics@2frame.com.br";
      $subject = "Consulta de orçamento";
      $header  = "From: danielle.steffen@2frame.com.br" . "\r\n";
      $header .= "Content-type: multipart/mixed;\r\n";
      $header .= " boundary=\"{$mime_boundary}\"";
      $header .= "MIME-Version: 1.0\r\n";
  
      $msg = "This is a multi-part message in MIME format.\n\n";
      "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
      "Mensagem enviada em " . date("d/m/Y") . ", os dados seguem abaixo:\n\n" . "Nome: $name\n\n" . "E-mail: $email \n\n" . "Telefone: $telephone \n\n" . "Dúvida: $question \n\n";
  
      $message .= "--{$mime_boundary}\n";
      "Content-Type: {$ftype};\n" . " name=\"{$fname}\"\n";
      //"Content-Disposition: attachment;\n" .
      //" filename=\"{$fileatt_name}\"\n" .
      "Content-Transfer-Encoding: base64\n\n";
      $data . "\n\n" . "--{$mime_boundary}--\n";
  
      if (isset($_POST['Enviar'])) {
          $res = mail($to, $subject, $msg, $header);
      }
      if ($res) {
          echo 'Mensagem enviada para ' . $to . '';
      } else {
          echo 'Por favor corrija seus erros.';
      }
  }
  ?&gt;
  </code></pre>