帶有文件附件的PHP表單 - 不會附加文件

[英]PHP Form with file attachment - wont attach file


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

這是我的pastebin文件: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 -->

1 个解决方案

#1


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.

文件存儲在$ _FILES中,而不是存儲在$ _POST中。因此對於初學者,您需要確保從正確的位置獲取文件。此外,我不相信它會附加。您需要正確創建電子郵件。

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.

你可能會對像PHPMailer這樣的現有庫好運。如果我沒記錯的話,它內置了將文件附加到電子郵件的工具。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/01/29/a82914113652b4fec6838a3dd4a48f05.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com