-2

This is as far as I have gotten. Can anyone tell me what I have missed? Why does it not attach the file?

This is my pastebin file: http://pastebin.com/ziwv9FzT

and the code from my file below:

<!-- form start -->
<?php
$error = false;
$sent = false;
if(isset($_POST['submit'])) {
        if(empty ($_POST['order']) || empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
                $error = true;
        } else {

                $to = "order@amezdigitaldesign.com";

                $order = trim($_POST['order']);
                $name = trim($_POST['name']);
                $email = trim($_POST['email']);
                $file = trim($_POST['file']);
                $message = trim($_POST['message']);

                $subject = "order form";

                $messages = "\r\n order: $order \r\n namn: $name \r\n epost: $email \r\n meddelande: $message";
                $headers = "from:" . $name;
                $mailsent = mail($to, $subject, $messages, $headers);

                if($mailsent) {
                        $sent = true;
                }
        }
}
?>
        <?php if($error == true) { ?>
        <p class="error"><b>Där var ett tomt fält i formuläret.<br>var god säg till att all information fylls i korrekt.</b></p>
        <?php } if($sent == true) { ?>
        <p class="sent"><b>Tack, din order har skickats.<br>Vi kommer kontakta dig snarast!</b></p>
        <?php } ?>

        <div id="banner">

                <form name="order" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
                        <label for="order">Ärende: *<br></label>
                        <select name="order">
                        <option value="Banner">Banner</option>
                        </select><br><br>

                    <label for="name">Namn: *<br></label>
                    <input type="text" name="name" size="15" />

                    <br><label for="email">Epost: *<br></label>
                    <input type="email" name="email" size="25" /><br>

                    <label for="file">Bifoga fil:<br></label>
                    <input type="file" name="file"/><br><br>

                    <label for ="message">Meddelande: *<br>
                    <i>(Skriv gärna så detaljerat som möjligt hur du vill att din<br>banner ska se ut, om du inte bifogar fil.)</i></label><br>
                    <textarea name="message" cols="45" rows="10"></textarea><br><br>
                    <input type="submit" name="submit" class="submit" value="Skicka"/>

                </form>

                <div style="clear:both;"></div>
        </div>
<!-- form end -->
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Attach a file, what file? This is similar to what you should be using >>> http://stackoverflow.com/a/12142631/ – Funk Forty Niner Jan 29 '14 at 16:29
  • possible duplicate of [Sending an uploaded file as attachment to email](http://stackoverflow.com/questions/12142461/sending-an-uploaded-file-as-attachment-to-email) – Rowland Shaw Jan 30 '14 at 08:55

1 Answers1

2

Files are stored in $_FILES not in the $_POST. So for starters, you need to ensure you're getting the file to attach from the correct location. Furthermore, I don't believe it would've attached anyway. You need to create your email correctly.

You'll probably have better luck with an existing library like PHPMailer. If I recall correctly, it has built in facilities for attaching files to an email.

Julio
  • 2,261
  • 4
  • 30
  • 56
  • Although you are right about `$_FILES` instead of `$_POST` for the uploaded file in question, the OP's question is about "attaching" a file to an E-mail. With what OP is using as code right now, will never be attached, even when making the proper changes. – Funk Forty Niner Jan 29 '14 at 16:34
  • Yes, that's why I added the "I don't believe it would attach anyway". I think using PHPMailer would make this task much easier for them. – Julio Jan 29 '14 at 16:51
  • Yep, that's for sure Louis. Good point. U.V. ;-) – Funk Forty Niner Jan 29 '14 at 16:53