title: Uploading an image from contact form and send as email attachement
body: <p>I am trying to add a new field in the contact us form field, but I am stumped on how to properly do this.  I simply need to have the uploaded file be sent as an attachment of the contact us email. Thanks in advance Rahul</p>
  
  <p>Here is my PHP code:</p>
  
  <pre><code>&lt;?php
  $submitted = FALSE;
  if ($_POST['contact_form']) {
  $submitted = TRUE;  // The form has been submitted and everything is ok so far…
  $name = htmlspecialchars($_POST['name'], ENT_QUOTES);
  $email = htmlspecialchars($_POST['email'], ENT_QUOTES);
  $country = htmlspecialchars($_POST['country'], ENT_QUOTES);
  $message = htmlspecialchars($_POST['message'], ENT_QUOTES);
  if ($name == "") {
  // if the name is blank… give error notice.
  echo "&lt;p&gt;Please enter your name.&lt;/p&gt;";
  $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
  }
  if ($email == "") {
  // if the email is blank… give error notice.
  echo "&lt;p&gt;Please enter your e-mail address so that we can reply to you.&lt;/p&gt;";
  $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
  }
  if ($country == "") {
  // if the country is blank… give error notice.
  echo "&lt;p&gt;Please enter your country.&lt;/p&gt;";
  $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
  }
  if ($message == "") {
  // if the message is blank… give error notice.
  echo "&lt;p&gt;Please enter a question.&lt;/p&gt;";
  $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
  }
  if ($_POST['email'] != "" &amp;&amp; (!strstr($_POST['email'],"@") || !strstr($_POST['email'],".")))
  {
  // if the string does not contain "@" OR the string does not contain "." then…
  // supply a different error notice.
  echo "&lt;p&gt;Please enter a valid e-mail address.&lt;/p&gt;";
  $submitted = FALSE;  // Set this to FALSE so that it the message is not sent.
  }
  
  $problemIn = '';
  
          $ip = $_SERVER['REMOTE_ADDR'];
          $url = (!empty($_SERVER['HTTPS']))
                ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] 
                 : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  
  $to = "rahul@test.com";  // Set the target email address.
  $header = "From: $email";
  $attention = "Someone has sent you question from your webpage!";
  $message = "Name: $name \n Country: $country \n Question: $message \n IP Address: $ip \n Link: $url \n";
  if ($submitted == TRUE)
  {
  mail($to, $attention, $message, $header);
  echo '&lt;script type="text/javascript"&gt;alert("Thank you. Your question has been sent.");&lt;/script&gt;';
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Here is my HTML code:</p>
  
  <pre><code>    &lt;form method="post" name="frmmail" id="frmmail" action="&lt;?php echo $_SERVER['SCRIPT_NAME'] ?&gt;" onSubmit="javascript: return validation();" eenctype="multipart/form-data"&gt;
      &lt;input name="name" id="txtname" value="" placeholder="Name" onfocus="if(this.value == 'Name')" class="usericon" /&gt;
      &lt;input name="email" id="txtmail" value="" placeholder="Email" onfocus="if(this.value == 'Email')" class="emailicon" /&gt;
      &lt;input name="country" id="txtcountry" value="" placeholder="Country" onfocus="if(this.value == 'Country')" style="margin:0" class="countryicon" /&gt;
      &lt;textarea name="message" id="txtmsg" placeholder="Your Comment/Question" onfocus="if(this.value == 'Your Question')" class="msgicon"&gt;&lt;/textarea&gt;
      &lt;input type="file" name="file" class="file" /&gt; 
       &lt;input type="submit" value="Submit" class="button" /&gt;
  &lt;input type="hidden" name="contact_form" value="submitted" /&gt;
      &lt;/form&gt;
  </code></pre>