0

Have got a simple HTML form with file upload field:

    <form action="<?php bloginfo('template_url'); ?>/demo-contacts.php" method="post" id="sky-form" class="sky-form" enctype="multipart/form-data">
      <header>Submit an <strong>Application!</strong></header>
      <fieldset>
        <div class="row">
          <section class="col col-6">
            <label class="label">Name</label>
            <label class="input"> <i class="icon-append icon-user"></i>
              <input type="text" name="name" id="name">
            </label>
          </section>
          <section class="col col-6">
            <label class="label">E-mail</label>
            <label class="input"> <i class="icon-append icon-envelope-alt"></i>
              <input type="email" name="email" id="email">
            </label>
          </section>
        </div>
        <div class="row">
          <section class="col col-6">
            <label class="label">Telephone Number</label>
            <label class="input"> <i class="icon-append icon-phone"></i>
              <input type="text" name="telephone" id="telephone">
            </label>
          </section>
          <section class="col col-6">
            <label class="label">Address</label>
            <label class="input"> <i class="icon-append icon-envelope-alt"></i>
              <input type="text" name="address" id="address">
            </label>
          </section>
        </div>
        <section>
          <label class="label">Subject</label>
          <label class="input"> <i class="icon-append icon-tag"></i>
          <input type="text" name="subject" id="subject" value="Technician Application">
          </label>
        </section>
        <section>
          <label class="label">Covering Letter</label>
          <label class="textarea"> <i class="icon-append icon-comment"></i>
            <textarea rows="4" name="message" id="message"></textarea>
          </label>
        </section>
    <div class="row">
          <section class="col col-6">
            <label class="label">Attach your CV</label>
            <label class="input"> <i class="icon-append icon-file"></i>
              <input type="file" name="cv" id="cv">
            </label>
          </section>
    </div>
    <input type="hidden" name="recipient" value="<?php the_field('contact_form_recipient'); ?>">
      </fieldset>
      <footer>
        <button type="submit" class="button">Send</button>
      </footer>
      <div class="message"> <i class="icon-ok"></i>
        <p>Your message was successfully sent!</p>
      </div>
    </form>

And have the following PHP to process the form which worked well prior to adding file upload field:

$EmailFrom = "email address here";
$EmailTo = Trim(stripslashes($_POST['recipient']));
$Name = Trim(stripslashes($_POST['name'])); 
$Subject = Trim(stripslashes($_POST['subject'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Telephone = Trim(stripslashes($_POST['telephone'])); 
$Address = Trim(stripslashes($_POST['address'])); 
$Message = Trim(stripslashes($_POST['message'])); 
$CV = Trim(stripslashes($_POST['cv'])); 

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
$Body .= "CV: ";
$Body .= $CV;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL= URL here\">";
}
else{
  echo "failed";
}

At present, the e-mail that comes through just states the name of the file that's been uploaded, i'd like to have the file attached to the email, could someone guide me please?

Thanks

Adrian
  • 285
  • 2
  • 14
  • This is a fair example of why it's a bad idea to call `mail()` yourself. I really do not advise continuing with this code - since you've tagged this with PHPMailer, how about [using it](https://github.com/PHPMailer/PHPMailer), since it comes with an example that does precisely what you're asking for, using less code than you have already? – Synchro Aug 16 '16 at 22:10
  • Thanks for the link, apologies but I thought this was something to do with phpmailer, this code was taken from css tricks. – Adrian Aug 16 '16 at 22:11
  • I don't see any "file" input or file-related code and the form's missing an enctype for it, if you're intending the user to choose a file from their own computer. – Funk Forty Niner Aug 16 '16 at 23:01
  • if you know how to ping someone; do. I can't be staring at this question for anymore than 10 mins, I too have other things to do. so use @ etc... – Funk Forty Niner Aug 16 '16 at 23:06
  • Possible duplicate of [Send File Attachment from Form Using phpMailer and PHP](http://stackoverflow.com/questions/11764156/send-file-attachment-from-form-using-phpmailer-and-php) – itzmukeshy7 Aug 17 '16 at 00:36
  • I think you're missing the form attribute `enctype=multipart/form-data`... – Praveen Aug 17 '16 at 01:07
  • @Fred-ii- sorry I have 2 forms in the same template and pasted the wrong HTML, original post edited above. – Adrian Aug 17 '16 at 09:55

0 Answers0